Ripgrep (rg)
A fast, modern replacement for grep
1. What is ripgrep?
ripgrep (command: rg) is a search tool that lets you search text inside files.
Think of it as:
grep, but much faster and smarter
It is especially popular among developers because it:
- Is extremely fast
- Respects
.gitignoreautomatically - Has simple, intuitive syntax
2. Why use ripgrep?
Compared to traditional grep, ripgrep:
- ⚡ Searches very fast (written in Rust)
- 🚫 Automatically ignores
.gitignorefiles - 📁 Searches directories recursively by default
- 🧠 Has sane defaults (no extra flags needed)
- 🛠️ Works well with editors (VS Code, Neovim, etc.)
3. Installing ripgrep
macOS (Homebrew)
Linux
Verify installation
4. Basic usage
4.1 Search for a word in the current directory
This:
- Searches all files
- Recursively
- Skips ignored files (
.gitignore,.ignore)
4.2 Search in a specific directory
4.3 Search in a specific file
5. Understanding the output
Example:
Meaning:
Matches are highlighted automatically.
6. Case sensitivity
Case-sensitive (default)
Case-insensitive
7. Search using regular expressions
ripgrep supports regex by default.
Example: match foo or bar
Match numbers
(No -E needed!)
8. Search only certain file types
By file extension
Exclude files
9. Search hidden files
By default, hidden files are ignored.
Include hidden files
Ignore .gitignore
10. Show only file names
Files that contain matches
Files that do NOT contain matches
11. Count matches
Count matching lines per file
Count total matches
12. Preview matches interactively (with fzf)
If you have fzf installed:
Or with preview:
13. Common beginner mistakes
❌ Using rg *
ripgrep does not need \*.
✅ Correct:
❌ Forgetting regex behavior
. means “any character”.
To search literal dots:
14. ripgrep vs grep (quick comparison)
| Feature | rg | grep |
|---|---|---|
| Recursive by default | ✅ | ❌ |
.gitignore aware |
✅ | ❌ |
| Speed | ⚡ | 🐢 |
| Regex by default | ✅ | ❌ |
15. When should you use ripgrep?
Use rg when you want to:
- Search codebases
- Find functions, variables, strings
- Replace
grep -R - Work fast in the terminal
16. Typical workflow example
Fast. Simple. Powerful.
17. Summary
ripgrep (rg) is:
- Fast
- Simple
- Powerful
- Developer-friendly
If you work with text or code, it’s one of the most useful CLI tools you can learn.