Commands · Command

CommandLinuxmacOS

grep

grep [options] pattern [file...]

Searches text — from a file or piped input — for lines matching a pattern, and prints the matches.

// FLAGS

-icase-insensitive
-rrecursive search through a directory
-vinvert match — show non-matching lines
-nshow line numbers
-ccount matches instead of printing them

// EXAMPLE

grep -ri "error" /var/log/syslog — finds every line containing "error" (any case) in the system log.

// GOTCHA

macOS ships BSD grep, not GNU grep — a few flags (like --include for filtering a recursive search by filename) aren't available out of the box unless GNU grep is installed separately.

// RELATED COMMANDS