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 *.php while 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 -c to 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 '^#'.

Frequently asked questions

When should I use ripgrep instead of grep?

Use ripgrep when searching a codebase or any directory that has a .gitignore file — rg automatically excludes ignored files and is significantly faster. Use grep when you need POSIX compatibility, are searching on a minimal system without rg, or are piping output from another command (grep is always available).

Does -F disable the whole regex engine?

Yes. With -F (--fixed-strings) the pattern is treated as a literal string, so characters like . + * ( ) [ ] are matched literally. This is useful when searching for variable names or code snippets that contain regex metacharacters.

What does -C (context) do exactly?

-C N prints N lines before and N lines after each matching line, with a -- separator between groups. -A and -B give asymmetric before/after context if you need only one side. -C cannot be combined with -c (count) — they produce incompatible output.

How do I search for two patterns at once?

With grep, pipe: grep "pattern1" file | grep "pattern2". Or use grep -E "pat1|pat2" for OR logic. With rg, use rg -e "pat1" -e "pat2" for OR, or pipe two rg calls for AND logic.

Why does my glob pattern not work?

Shell glob expansion may be intercepting the pattern before grep/rg sees it. Wrap it in single quotes: --include='*.php'. This builder outputs single-quoted globs by default.