grep

grep searches for a pattern in a file.

grep 'pattern' <file>

Flags

  • -v — omit matching lines
  • -x — exact match
  • -r — recursive
  • -n — line numbers
  • -w — word match

Context

-A <n> prints n lines after the match.

-B <n> prints n lines before the match.

Find file with content

grep -rnw ['<directory>'] -e <["]pattern["]>

Multiple

<term_1>/|<term_2>
Updated: 2026 Aug 19