Search recursively for text in files
grep -Rnw '/path/to/somewhere/' -e 'pattern'
-r or -R is recursive ; use -R to search entirely-n is line number, and-w stands for match the whole word.-i is for case insensitive-l (lower-case L) can be added to just give the file name of matching files.-e is the pattern used during the searchUsed in-line on the CLI (Bash, Shell, etc). The following will pipe the output of APT into grep where it'll filter down to lines containing “php”
apt list --installed | grep php
Grep a file, then execute another command depending on grep's response. This example will prevent duplicate lines in config.txt
grep -qxF 'config line 1' config.txt || echo 'config line 1' >> config.txt
-q be quiet-x match the whole line-F pattern is a plain string