What is Ripgrep?
ripgrep (binary: rg) is a line-oriented search tool written in Rust. It searches your current directory recursively for a regex pattern, while respecting your .gitignore rules.
Created by: Andrew Gallant ("BurntSushi") in 2016
Primary goal: Replace interactive grep -r usage for developers with something faster, smarter, and easier.
Why It Was Built
Traditional grep was designed in an era before:
- Modern multi-core CPUs
- Version-controlled projects with
node_modules(300,000 files) - Common project conventions for ignoring build artifacts
Every developer who has searched a repo with grep -r has typed a variant of:
grep -rn "pattern" . \
--exclude-dir=node_modules \
--exclude-dir=.git \
--exclude="*.min.js" \
--include="*.ts"
With rg, the equivalent is:
rg "pattern"
All those excludes are automatic because rg reads .gitignore.
Core Differences From grep
| Behavior | grep default | rg default |
|---|---|---|
| Recursion | No (single file) | Yes |
.gitignore | Not respected | Respected |
| Hidden files | Included | Excluded |
| Output coloring | No | Yes |
| Line numbers | No | Yes |
| File grouping | No | Yes |
| Threading | Single-core | Multi-core |
Architecture: Why It Is So Fast
rg achieves its speed through three mechanisms:
1. Parallel Directory Traversal It uses a thread pool to search multiple directories simultaneously, fully utilizing multi-core processors.
2. Literal Optimization
Before running the full regex engine, rg extracts any literal substrings from your pattern and uses SIMD instructions (via the memchr crate) to skip non-matching sections at CPU cache speed. The regex is only evaluated on lines that already contain the literal.
3. Smart Skip Lists
Because rg reads .gitignore before it traverses directories, it prunes entire subtrees from the search queue before a single byte of those files is read from disk.
When to Use rg vs grep
Use rg for code and interactive searches:
- Searching a project repository
- Refactoring across many files
- Any search where you want readable, grouped output
Use grep for scripts and log streaming:
- Shell scripts deployed to servers without
rg - Piping
tail -foutput through a filter - POSIX portability requirements