grep

Search for patterns in files. Supports regex, recursion, context lines, and powerful filtering.

Synopsis

grep [options] 'pattern' file(s)

Core Options

-r

Recursive search through directories.

-i

Ignore case.

-n

Show line numbers.

-v

Invert match (exclude pattern).

-E

Use extended regex (egrep).

-F

Fixed string search (faster for literals).

-C N

Show N lines of context around matches.

--include

Limit files by glob (e.g., *.log).

-m N

Stop after N matches per file.

Usage Examples

Basic Search

Find all lines containing 'error' in app.log.

grep 'error' app.log

Recursive Search with File Filter

Search TODO in JS files only.

grep -r --include='*.js' 'TODO' .

Fixed String

Search a literal string without regex parsing.

grep -F 'foo.bar' config.txt

Context Lines

Show 2 lines before and after each match.

grep -C 2 'exception' error.log

Count Matches

Count lines with 404 status.

grep -c ' 404 ' access.log
Built for builders.