grep / ripgrep Command Builder
Build a grep or ripgrep (rg) command without memorising dozens of flags. Select your tool, enter a pattern and path, tick the options you need — context lines, glob filters, invert — and a syntactically correct command appears instantly. ripgrep is recursive by default and uses -g globs; GNU grep needs -r and --include. Both differences are handled automatically.
How to use the grep / ripgrep Command Builder
Select grep or ripgrep (rg). Enter a search pattern — regular expression by default; tick Fixed string to disable regex interpretation. Set the path (defaults to the current directory .).
The File glob field filters which files are searched: *.php, *.{ts,tsx}. For grep this maps to --include='*.php'; for rg it maps to -g '*.php'. The Exclude glob adds --exclude-dir for grep or -g '!vendor' for rg.
Recursive adds -r to grep (rg is always recursive so the checkbox has no effect there). Context lines adds -C N to show N lines before and after each match — useful for understanding matches in context. Count (-c) prints the number of matching lines per file instead of the lines themselves; it cannot be combined with context lines.
Click Example to see a real-world command assembled from typical options, then click Copy to paste it into your terminal.
About grep and ripgrep
grep (Global Regular Expression Print) has been on UNIX systems since 1974. It scans files for lines matching a pattern and prints them. GNU grep — the version on Linux and available on macOS via Homebrew — supports POSIX BRE/ERE, Perl-compatible regexes (-P), and dozens of flags for controlling output format, color and performance. BSD grep (macOS default) is broadly compatible but lacks a few GNU flags like -P.
ripgrep (rg) is a modern replacement written in Rust. It respects .gitignore and .rgignore files automatically, is recursive by default, uses SIMD for vectorised search, and is typically 5-100x faster than GNU grep on large codebases. It uses -g for include/exclude glob patterns (a single flag can both include and exclude with the ! prefix) and outputs colour by default.
Knowing which flags differ between the two prevents frustrating errors. The most common gotchas: rg does not need -r (and ignores it); grep's --include takes a glob while rg's -g takes a potentially negated glob; -F (fixed string) and -i (ignore-case) work in both; -w (word boundary) works in both but is implemented differently. This builder translates your choices into the correct syntax for whichever tool you target.
Common use cases
- Search source code — recursively grep a repo for a function name, limiting to
*.phpwhile excluding the vendor directory. - Log analysis — grep an access log for HTTP 500 errors with 3 lines of context to see the request that caused each error.
- Config auditing — search all YAML files for a deprecated key across a monorepo using ripgrep's gitignore awareness.
- Counting occurrences — use
-cto count how many files contain a TODO comment, sorted by count with a shell pipe. - Fixed-string search — search for a literal string that contains regex metacharacters (e.g.
$HOME) without escaping them, using-F. - Invert filtering — strip comment lines from a config file output by grepping with
-v '^#'.