ripgrep (rg) vs grep
What is ripgrep?
ripgrep is a line-oriented search tool written in Rust, built to do the same job as grep but faster and with better defaults for working inside a codebase.
1
rg -i -n "TODO" ./
That’s it. No flags needed to search recursively (if using grep, we need to explicit the -r flag), and it already skips the stuff you almost never want to search.
The main differences
1. Recursive by default
With grep you need -r to search a whole directory:
1
grep -r "TODO" .
With rg, recursive is the default behavior:
1
rg "TODO"
2. Follow .gitignore rule automatically
grep -r will search inside node_modules, .git, build artifacts, everything. rg reads your .gitignore (and .ignore) files and skips all of that automatically:
1
2
rg "TODO" # skips node_modules, .git, dist, etc.
grep -r "TODO" . # searches everything, including junk
If you actually want to search ignored files too, you can force it:
1
rg -uu "TODO"
3. Speed
rg is built on Rust’s regex engine with automatic parallelism and smart filtering (skipping binary files, ignored files, etc.), so on large repos it’s much more faster than a plain grep -r.
4. Better output by default
Line numbers, colored matches, and grouping by file all come out of the box with rg:
1
2
3
4
rg "TODO"
src/main.rs
12: // TODO: handle error case
45: // TODO: refactor this later
With grep you’d need to add -n and --color yourself.
Quick install
1
2
# debian/ubuntu
sudo apt install ripgrep