Search and Filtering

grep

Searches text for matching patterns.

grep filters lines by text or regular expression. It is one of the core tools for finding relevant output.

Syntax
grep [options] pattern [file...]

Arguments explained

  • pattern is the text or regex to search for.
  • file is optional; grep can read standard input.
  • -i ignores case.
  • -r searches directories recursively.
  • -n shows line numbers.
  • -E enables extended regular expressions.

Common examples

Search a log
grep -n "error" app.log

Shows matching lines with line numbers.

Filter process output
ps aux | grep nginx

Finds process lines containing nginx.

grep Command
FieldDetails
Commandgrep
CategorySearch and Filtering
Primary useSearches text for matching patterns.
Syntaxgrep [options] pattern [file...]