🐧 Linux / Shell Scripting
Beginner
How do you search for text within files?
Answer
Use grep (global regular expression print). grep "pattern" filename searches a single file. grep -r "pattern" /dir searches recursively in a directory. grep -i makes the search case-insensitive. grep -n shows line numbers. grep -l shows only filenames with matches. grep -v inverts — shows lines that do NOT match. grep -c counts matching lines. For multiple files: grep "error" /var/log/*.log. egrep or grep -E enables extended regular expressions. fgrep or grep -F treats the pattern as a literal string (faster).