Basic and case-insensitive search
Search one file
grep "ERROR" app.log
Example:
grep -i "timeout" app.log
Count matches
grep -c "WARN" app.log
Example:
grep -n "panic" app.log
Recursive code search
Search all files in current project
grep -R "TODO" .
Example:
grep -R --include="*.js" "useEffect" src
Exclude directories
grep -R --exclude-dir=node_modules "SECRET" .
Example:
grep -R --exclude="*.min.js" "token" web
Context and regex usage
Show lines before and after match
grep -C 2 "Exception" server.log
Example:
grep -A 3 -B 1 "failed" syslog
Extended regex patterns
grep -E "GET|POST|PUT" access.log
Example:
grep -E "[0-9]{3}" codes.txt
Common mistakes / Errores comunes
- For huge projects, grep -R . without excludes can be very slow.
- Shell may expand patterns unexpectedly; quote regex expressions.
- Binary files can pollute output; use --binary-files=without-match when needed.
Last updated: February 2026