Grep Cheat Sheet

Grep cheat sheet with the most common and useful Grep commands.

grep [0] is a command-line utility for searching plain-text data sets for lines that match a regular expression. That makes grep one of the essential Linux commands.

Syntax

The general grep command syntax:

grep [OPTIONS] PATTERN [FILE...]

In Document

grep for foo in bar.txt:

$ grep foo bar.txt

Recursive

grep recursively for foo in all subdirectories:

$ grep -R "foo" .

grep recursively (case insensitive) for foo in all subdirectories:

$ grep -Ri "foo" .

grep recursively for foo in all subdirectories and return the file name only:

$ grep -R -I "foo" .

References

  1. https://www.gnu.org/software/grep/manual/grep.html