grep Options
-i, -n, -c, -v and -r.
Grep has dozens of options, but five of them cover almost everything you'll need. Let's try each one on the server log.

- Dozens of options
- Five cover almost everything
- Let's try them
Ignore case, and line numbers
Grep is case sensitive. Error with a small E finds nothing, because the log says ERROR in capitals. Dash I ignores case. And dash N adds the line number in front of every match, so you know exactly where it is.
grep error logs/server.log grep -in error logs/server.log 1:2026-01-05 09:00:23 ERROR priya failed /home 16:2026-01-05 09:07:00 ERROR jo failed /shop 22:2026-01-05 09:09:18 ERROR priya failed /home 26:2026-01-05 09:11:08 ERROR priya failed /home 42:2026-01-05 09:17:21 ERROR alex failed /shop 43:2026-01-05 09:17:56 ERROR alex failed /home 54:2026-01-05 09:23:28 ERROR priya failed /cart
Count, and invert
Dash C counts the matching lines, instead of printing them. Sam appears on eighteen lines. Dash V inverts the search. It prints the lines that don't match. Here, every line that isn't INFO, which leaves the warnings and errors. There are sixteen, so we only show the first six, using head.
grep -c sam logs/server.log 18 grep -v INFO logs/server.log | head -n 6 2026-01-05 09:00:23 ERROR priya failed /home 2026-01-05 09:03:58 WARN jo slow page /cart 2026-01-05 09:04:48 WARN alex slow page /home 2026-01-05 09:07:00 ERROR jo failed /shop 2026-01-05 09:07:18 WARN alex slow page /shop 2026-01-05 09:08:10 WARN alex slow page /cart
Search a whole folder
Dash R searches every file in a folder, and the folders inside it. Grep prints the file name before each match, so you know where it was found. Here we look for the word Linux, everywhere in our home folder.
grep -r Linux . ./Documents/cv.txt:Skills: Linux, Python, Git ./notes.txt:Learn Linux
Summary
Dash I ignores case, dash N numbers lines, dash C counts, dash V inverts, and dash R searches folders. Next, a grep challenge, on the server log.
Key takeaways- -i ignore case
- -n line numbers
- -c count, -v invert, -r folders