Basic

Find word.

grep foo PATH

Exact match

grep -w 'foo' bar.txt

Invert match

grep -v 'foo' bar.txt

That will invert the match on each line.

If you want to want to find entire files which do not match a pattern, use:

grep -L 'foo' bar.txt baz.txt

Regex

There are three types of regex:

  1. basic (BRE)
  2. extended (ERE)
  3. perl (PCRE)

The basic one supports matching such as these:

grep '\sfoo' PATH

Blank line

grep '^$' filename