Copied to clipboard

grep

grep is a common command-line tool used for searching for matching text content in files and outputting the results.

Example

  • grep 'hello' file.txt, search for lines containing hello in file.txt.
  • grep -r 'world' dir/, recursively search for lines containing world in dir/ directory and its subdirectories.
  • grep -n 'error' file.txt, search for lines containing error in file.txt and display line numbers.
  • grep -i 'apple' file.txt, search for lines containing apple in file.txt, ignoring case.
  • grep -E '[0-9]{3}' file.txt, search for lines containing three consecutive digits in file.txt.