Tools

grep Cheat Sheet

Print-ready cheat sheet for grep, organized for fast lookup, study, and desk-side use

Source
GNU grep Manual (gnu.org/software/grep)
License
MIT
Updated
2026-03-27

Sample

What's in this cheat sheet

  • Basic Usage
  • Regex Patterns
  • Extended Regex
  • Context Lines
  • Recursive Search
  • Counting & Listing
  • Inverse Match
  • Multiple Patterns
  • Performance
  • Common Patterns

Running grep

grep "pattern" file.txt            # search in file
grep "error" *.log                 # search multiple files
grep "hello" file1.txt file2.txt   # explicit file list
cat file.txt | grep "pattern"      # pipe input
dmesg | grep -i "usb"              # filter command output

Common Flags

-iCase-insensitive matching
-vInvert match — print non-matching lines
-cPrint count of matching lines
-nShow line numbers
-lList filenames with matches only
-LList filenames without matches
-wMatch whole words only
-xMatch whole lines only

Download the full cheat sheet for all sections, formatted for print

Download PDF

Downloads

Choose the treatment that matches how you read