grep
What is grep?
grep: Global Regular Expression Print — Search for a pattern inside files or command output. grep searches for text or patterns in files and command output. grep -r "TODO" src/ finds every TODO under src, and grep -i error app.log finds error lines regardless of case. Useful options include -n for line numbers, -v to show lines that do not match, -c to count matches, -l to list only file names, and -C 3 to show three lines of context around each match.
Frequently asked questions about grep
What should you keep in mind with grep?
It shines in pipelines. docker logs web | grep -i exception filters a container's output, and ps aux | grep php finds running PHP processes. For searching large codebases, ripgrep (rg) is a faster modern alternative that respects .gitignore by default. Both are worth having in your fingers, because they work on every server you will log into.
At a glance
| Category | CLI commands |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |