general regular expression print // file pattern searcher

Flags worth learning 🧠

-o Print only the matching string, not the entire line

-l Only print filename of matching files

-h Hide filename of matching files

-c Show the number of matches found

-m Limit to <num> matches. Surprisingly useful to avoid firehoses.

--line-buffered Stops grep buffering data, and output it as soon as it arrives

Niche flags

-f Pass in a file of newline-separated patterns. Note: empty lines match every input line.

-w Match whole words only

-P Set PCRE, useful when you're writing a complex pattern

--color This is enabled by default for grep, but not for flavours like fgrep/egrep.

-B/ -A Show <num> lines before and after matches

-h /-H Do/don't print filename. -H defaults on when searching multiple files

Useful flags I already use

-v Display all entries which don't match

-r Search recursively in a directory

-n Show line numbers

Grep Flavours