Let's think about it this way for a second
grep pattern file finds and prints the lines in file that contain pattern (grep stands for 'global regular expression print' — a confusing name, but simple to use). The -i flag makes the search case-insensitive. The -r flag searches an entire folder, including all sub-folders. The -n flag shows the line number alongside each match — so you instantly know which line an error is on inside a huge file. The -v flag does the opposite — it shows only the lines that don't contain the pattern.
Let's connect this to a real-world scenario
If you just want to see the error lines in a big log file, type grep -n "ERROR" app.log. If you want to find which files across your whole project folder still have leftover TODO comments, grep -rn "TODO" . scans every folder and prints the file name plus line number for each — this is one of the most commonly used commands during code review. Combined with a pipe (from the last chapter), grep also plays a big role in workflows like finding processes with ps aux | grep nginx.
Let's try it together in the terminal
grep "ERROR" app.log
grep -in "error" app.log
grep -rn "TODO" .
grep -v "DEBUG" app.log > errors-only.logLines containing 'ERROR' will show up in the terminal along with their line numbers.5-Minute Try-It
Write 5 lines in a notes.txt file (put TODO in one of them). Search for it with grep -n TODO notes.txt.
A Quick Word of Caution
If your grep pattern contains special characters (., *, [, etc.), they can automatically be interpreted as regex — if you want to search for a literal dot, you can use grep -F (fixed string).