How to search with grep
Overview
grep prints lines matching a pattern. It can search one file, many files, or text received through a pipe.
Examples
grep 'error' app.log
grep -i 'ubuntu' notes.txt
grep -n 'TODO' *.txt
grep -R --include='*.py' 'print(' .
ps aux | grep firefox
Useful options
-iignores letter case-nprints line numbers-vselects non-matching lines-wmatches whole words-Rsearches directories recursively-Eenables extended regular expressions
Tips
Quote patterns to protect spaces and special characters from the shell. Start with literal words before learning regular expressions.
A status of 1 often simply means no lines matched; it is not necessarily a failure.