ripgrep (rg) — Recursively Search Directories with Regex
ripgrep recursively searches directories for a regex pattern while respecting your gitignore. Written in Rust, ripgrep is the fastest search tool on the market — used inside VS Code, GitHub, and many other dev tools.
What it is
ripgrep (rg) is a line-oriented search tool that recursively searches directories for a regex pattern while respecting your .gitignore rules. Written in Rust, ripgrep is consistently the fastest search tool in benchmarks. It is used inside VS Code for workspace search, on GitHub for code search, and by developers who need to search large codebases quickly.
ripgrep targets developers and system administrators who search through code and text files regularly. It replaces grep, ack, and the silver searcher (ag) with faster performance and smarter defaults.
How it saves time or tokens
ripgrep is fast because it uses Rust's regex engine, parallelizes directory traversal, and skips files matched by .gitignore automatically. On large codebases, ripgrep finishes searches in seconds where grep takes minutes. Smart defaults like ignoring binary files, hidden files, and gitignored paths mean you get relevant results without complex flag combinations. Unicode support is built in.
How to use
- Install ripgrep:
brew install ripgrep # macOS
sudo apt install ripgrep # Debian/Ubuntu
cargo install ripgrep # From source
- Search recursively from the current directory:
rg pattern # Search all files recursively
rg -i pattern # Case-insensitive search
rg -t py 'def main' # Search only Python files
rg -g '*.json' 'version' # Search by glob pattern
- Advanced usage:
rg --json pattern # Machine-readable JSON output
rg -C 3 pattern # Show 3 lines of context
rg -l pattern # List matching files only
rg --stats pattern # Show search statistics
Example
# Find all TODO comments in a project, excluding node_modules
rg 'TODO|FIXME|HACK' --type-not json
# Search for a function definition across languages
rg 'def\s+process_data|func processData|function processData'
# Count matches per file
rg -c 'import' --sort path
# Replace across files (preview with --dry-run)
rg 'old_function' -l | xargs sed -i 's/old_function/new_function/g'
Related on TokRepo
- AI Tools for Coding — Developer productivity tools
- Featured Workflows — Top-rated CLI tools and workflows
This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.
For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.
Common pitfalls
- ripgrep respects
.gitignoreby default; if you need to search ignored files, use the--no-ignoreflag explicitly. - Binary files are skipped automatically; to search binary files, use
--binaryor-aflags. - ripgrep uses Rust regex syntax, which differs slightly from PCRE; features like lookaheads require the
--pcre2flag (and the PCRE2 library must be installed).
Frequently Asked Questions
ripgrep is typically 2-10x faster than GNU grep on large directories, depending on the workload. It achieves this through parallel directory traversal, memory-mapped file reading, and an optimized regex engine. On repositories with many gitignored files, the speedup is even larger.
Yes. ripgrep uses Rust's regex engine by default, which supports most common regex features. For advanced features like lookaheads and backreferences, enable PCRE2 mode with the --pcre2 flag.
By default, ripgrep skips files matched by .gitignore, hidden files (starting with .), and binary files. This behavior produces cleaner results for code searches. Use --no-ignore, --hidden, and --binary flags to override.
Yes. ripgrep handles the same core use cases as grep with faster performance and better defaults. The command syntax differs slightly (rg instead of grep -r), but most common patterns translate directly.
Yes. VS Code uses ripgrep as its backend for workspace search (Ctrl+Shift+F / Cmd+Shift+F). This is why VS Code's search is fast even in large projects with many files.
Citations (3)
- ripgrep GitHub— ripgrep recursively searches directories while respecting gitignore
- VS Code Search Documentation— VS Code uses ripgrep for workspace search
- ripgrep Blog Post— ripgrep benchmark comparisons with grep, ag, and ack
Related on TokRepo
Discussion
Related Assets
Moodle — Open-Source Learning Management System
The most widely used open-source learning platform, providing course management, assessments, and collaboration tools for educators and organizations worldwide.
Sylius — Headless E-Commerce Framework on Symfony
An open-source headless e-commerce platform built on Symfony and API Platform, designed for developers who need a customizable and API-first commerce solution.
Akaunting — Free Self-Hosted Accounting Software
A free, open-source online accounting application built on Laravel for small businesses and freelancers to manage invoices, expenses, and financial reports.