grep
Search for patterns in files. Supports regex, recursion, context lines, and powerful filtering.
Synopsis
grep [options] 'pattern' file(s)
Core Options
-rRecursive search through directories.
-iIgnore case.
-nShow line numbers.
-vInvert match (exclude pattern).
-EUse extended regex (egrep).
-FFixed string search (faster for literals).
-C NShow N lines of context around matches.
--includeLimit files by glob (e.g., *.log).
-m NStop after N matches per file.
Usage Examples
Basic Search
Find all lines containing 'error' in app.log.
grep 'error' app.logRecursive 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.txtContext Lines
Show 2 lines before and after each match.
grep -C 2 'exception' error.logCount Matches
Count lines with 404 status.
grep -c ' 404 ' access.logBuilt for builders.