Master grep to search files and streams from the shell. 18.03.2026 | reading time: 2 min You are staring at a mountain of logs; grep helps you find the one line that matters and act on it immediately. Real-world log triage Hunt for problem lines and show line numbers with this concrete example. ``` grep -n --color=auto "ERROR" /var/log/syslog # sample output 12:Mar 18 12:01:23 server myapp[1234]: ERROR Connection failed 47:Mar 18 12:03:01 server cron[5678]: ERROR backup failed ``` This command locates "ERROR" occurrences, prints file line numbers and highlights matches so he can jump to the exact spot. Power switches to know Make grep work harder: use `-i` for case-insensitive, `-v` to invert matches, `-n` for line numbers, `-c` to count matches, `-l` to list files, `-o` to print only matched text, `-E` for extended regex or `-P` for Perl regex, and `-A`/`-B`/`-C` to include context lines; combine `--color=auto` to see hits quickly. Combine and automate Pipe and chain: `ps aux | grep pattern` finds running processes, `find /var/log -type f -exec grep -H "pattern" {} +` searches many files, or use `grep -R` for recursion; pair grep with `awk`, `sed` or `xargs` to extract, edit or delete matched items in scripts and cron jobs. Alternatives and complements For speed on large trees try ripgrep, for structured field extraction use awk, for inline edits sed is ideal, and for whole-repository searches consider tools integrated with version control; choose the tool that fits file size, speed and regex needs. Where to go next Start applying grep to real troubleshooting tasks and build shell scripts that save minutes every day; to formalize that skillset consider deeper Linux training and certifications like CompTIA Linux+ or LPIC-1, with bitsandbytes.academy offering intensive exam preparation. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting troubleshooting filesystem