Comparisons / grep

ripgrep vs grep

grep is the POSIX standard — available everywhere, battle-tested, and reliable. ripgrep is the modern replacement — dramatically faster, developer-friendly, and smarter by default.

Quick Verdict

For interactive developer use, ripgrep is the better default — it's 2–33× faster in the benchmarks in ripgrep's README, smarter about which files to search, and more ergonomic. The main reason to prefer grep is when you need POSIX portability in scripts that run on systems where you can't install ripgrep. If you control the environment, use ripgrep.

Feature Comparison

Feature ripgrep grep (GNU)
Speed (large codebase) ✅ Fastest 🐢 2–33× slower in upstream tests
Respects .gitignore ✅ Yes (default) ❌ No
Skips hidden files ✅ Yes (default) ❌ No
Skips binary files ✅ Yes (default) ⚠️ Sometimes
Unicode support ✅ Always on ⚠️ Locale-dependent
PCRE2 regex ✅ With -P ✅ With -P (GNU)
File type filtering ✅ -t flag ❌ Manual globs only
Compressed file search ✅ With -z ❌ No
Single binary ✅ Yes ✅ Yes
JSON output ✅ --json ❌ No
Config file ✅ Via RIPGREP_CONFIG_PATH ❌ No (GREP_OPTIONS removed in 3.6)
POSIX compliant ❌ No ✅ Yes
Actively maintained ✅ Yes ✅ Yes

Speed

In the benchmarks in ripgrep's README, GNU grep is 2–33× slower, depending on the pattern and locale. Searching the Linux kernel source with equivalent filtering, ripgrep takes 0.063 s vs grep's 0.674 s (10.69×). On a ~13 GB file, it takes 1.042 s vs 6.577 s (6.31×).

The gap narrows to about 2× with very many matches, or with a no-literal pattern in the C locale. That same no-literal pattern is the widest gap, at 32.74×, when grep runs in a Unicode locale.

See the full benchmarks page for detailed data across different patterns and corpus sizes.

When to use each

Use ripgrep when:

  • ✓Searching code repositories
  • ✓You want smart defaults (skip node_modules, dist, etc.)
  • ✓Speed matters on large codebases
  • ✓You want file-type filtering (-t py)
  • ✓You want JSON output for scripting
  • ✓Daily interactive terminal use

Stick with grep when:

  • →Writing POSIX-portable shell scripts
  • →Searching on systems where you can't install ripgrep
  • →You specifically need POSIX ERE or BRE syntax
  • →Embedded systems or minimal environments

Command Equivalents

Most grep commands have a direct ripgrep equivalent. One key difference: ripgrep searches recursively by default, so you rarely need to specify a path.

Task ripgrep grep
Basic search rg 'pattern' grep -r 'pattern' .
Case-insensitive rg -i 'pattern' grep -ri 'pattern' .
Show line numbers rg -n 'pattern' grep -rn 'pattern' .
Word boundary rg -w 'word' grep -rw 'word' .
Invert match rg -v 'pattern' grep -rv 'pattern' .
Count matching lines rg -c 'pattern' grep -rc 'pattern' .
List matching files rg -l 'pattern' grep -rl 'pattern' .
Context (3 lines) rg -C 3 'pattern' grep -rC 3 'pattern' .
Only Python files rg -t py 'pattern' grep -r --include='*.py' 'pattern' .
Exclude directory rg -g '!dist' 'pattern' grep -r --exclude-dir=dist 'pattern' .
Fixed string (no regex) rg -F 'literal.string' grep -rF 'literal.string' .
Search hidden files rg -. 'pattern' grep -r 'pattern' .

Migration Tips

Switching from grep to ripgrep is straightforward. Most flags are identical or near-identical. The main adjustment is that ripgrep is recursive by default — you don't need -r or a path argument.

# grep habit → ripgrep equivalent

# grep -rn 'pattern' .
rg 'pattern'          # -r and . are implicit

# grep -rni 'pattern' .
rg -i 'pattern'       # -r and -n are default

# grep -rl 'pattern' .
rg -l 'pattern'

# grep -r --include='*.py' 'pattern' .
rg -t py 'pattern'    # much more ergonomic

# grep -r --exclude-dir=node_modules 'pattern' .
rg 'pattern'          # node_modules already excluded via .gitignore