ripgrep (rg) is a line-oriented recursive search tool written in Rust that searches directories for regex patterns at exceptional speed. It was created to give developers a smarter default experience than traditional grep: it automatically respects .gitignore rules, skips hidden files and binary files, uses parallel multi-threaded search, and delivers full Unicode support without sacrificing speed. The key mental model is that ripgrep operates in two distinct modes β a blazing-fast default engine using finite automata (guaranteeing linear-time search) and an optional PCRE2 mode that enables look-around and backreferences at the cost of potentially slower, backtracking-based matching. Understanding this distinction explains nearly every performance characteristic and feature limitation you will encounter.
What This Cheat Sheet Covers
This topic spans 20 focused tables and 132 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Basic Pattern Search
The foundation of ripgrep is a simple, ergonomic search invocation: provide a pattern and an optional path. By default, ripgrep recursively searches the current directory, treats the pattern as a regex, displays line numbers, groups results by filename, and highlights matches in color. These defaults are intentionally developer-friendly and differ meaningfully from POSIX grep.
| Command | Example | Description |
|---|---|---|
rg 'TODO' | Recursively searches the current directory for the pattern; shows file names, line numbers, and highlighted matches. | |
rg 'TODO' src/main.rs | Searches only the specified file instead of the whole directory tree. | |
rg 'TODO' src/ | Restricts recursive search to the given directory. | |
cat file.log | rg 'ERROR' | ripgrep detects piped stdin automatically and searches it like a file. | |
rg -e 'TODO' -e 'FIXME' | Matches lines containing any of the specified patterns; each -e adds another alternation. | |
rg -f patterns.txt src/ | Reads one pattern per line from the file and searches for all of them simultaneously. |