How to Search Text With grep in Linux

grep searches input (files or piped text) for lines matching a pattern and prints those lines.

Published September 30, 2026

grep searches input (files or piped text) for lines matching a pattern and prints those lines.

Key points

  • grep -i performs a case-insensitive search
  • grep -r searches recursively through every file in a directory tree
  • grep -n shows the line number of each match, useful when searching source code

Example

grep -rn "TODO" ./src
More Linux articles