grep Cheatsheet

Top patterns.

Overview

grep is the line-matching tool that anchors Unix text search. Five primitive surfaces cover almost every operational use: regex pattern matching, recursive directory traversal, surrounding context, inverted matches, and word/line anchors for precision. rg (ripgrep) and ag (the silver searcher) are faster modern alternatives on large trees; the BSD/GNU grep on every Unix box covers everywhere else.

The approach

Five idioms cover almost every operational use of grep. Memorising them moves the team from copy-pasted commands to confident text investigation.

Why this compounds

Each grep one-liner replaces a manual scroll through a log file. The team’s text-search fluency deepens; regex skills transfer to sed, awk, log queries, and code-aware tooling.