ScriptsApr 11, 2026·2 min read

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.

TL;DR
ripgrep searches directories recursively for regex patterns at speeds that beat grep, ag, and ack.
§01

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.

§02

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.

§03

How to use

  1. Install ripgrep:
brew install ripgrep        # macOS
sudo apt install ripgrep    # Debian/Ubuntu
cargo install ripgrep       # From source
  1. 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
  1. 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
§04

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'
§05

Related on TokRepo

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.

§06

Common pitfalls

  • ripgrep respects .gitignore by default; if you need to search ignored files, use the --no-ignore flag explicitly.
  • Binary files are skipped automatically; to search binary files, use --binary or -a flags.
  • ripgrep uses Rust regex syntax, which differs slightly from PCRE; features like lookaheads require the --pcre2 flag (and the PCRE2 library must be installed).

Frequently Asked Questions

How fast is ripgrep compared to grep?+

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.

Does ripgrep support regular expressions?+

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.

Why does ripgrep skip some files?+

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.

Can I use ripgrep as a grep replacement?+

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.

Is ripgrep used in VS Code?+

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)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets