ripgreb
Recursively search directories for a regex pattern
SYNOPSIS
rg [OPTIONS] PATTERN [PATH...]
PARAMETERS
-i, --ignore-case
Perform a case-insensitive search.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-l, --files-with-matches
Print only the names of files containing matches, one per file.
-L, --files-without-matches
Print only the names of files that do not contain matches, one per file.
-w, --word-regexp
Force PATTERN to match only whole words.
-F, --fixed-strings
Interpret PATTERN as a literal string instead of a regular expression.
-g, --glob GLOB
Include or exclude files based on glob patterns. Can be specified multiple times.
-u, --unrestricted
Search hidden files and files ignored by VCS (e.g., .gitignore). Use multiple times for more unrestricted search.
-C NUM, --context NUM
Show NUM lines of context before and after matching lines.
-N, --no-line-number
Suppress the printing of line numbers.
--pretty
Prints results in a user-friendly, formatted way, often with syntax highlighting.
-r REPLACEMENT, --replace REPLACEMENT
Replace matches with the specified string. This does not modify files.
DESCRIPTION
Ripgrep (rg) is a command-line utility for searching text patterns, renowned for its exceptional speed and user-friendliness. Written in Rust, it leverages a highly optimized regex engine and smart defaults to deliver a superior search experience compared to traditional tools like `grep`. `rg` recursively searches directories by default, respects .gitignore rules, and automatically skips binary files, making it ideal for codebases. It is designed for developers, offering features like line numbers, context, and intelligent file filtering. Its performance gains come from careful algorithmic choices, parallel processing, and memory mapping, making it a popular choice for large codebases and quick searches.
CAVEATS
While ripgrep is incredibly fast and feature-rich, it's important to note a few things. It prioritizes speed and convenience, meaning some niche features of `grep` might not be directly available or behave differently (e.g., `-z` for gzipped files requires external tools). Its default behavior of respecting .gitignore and skipping hidden/binary files can sometimes lead to unexpected "no results" if the user isn't aware of these smart defaults; the -u flag can be used to override this. Additionally, while optimized, searching extremely large binary files without filtering can still consume significant resources.
KEY FEATURES
Ripgrep comes with intelligent defaults, automatically skipping hidden files and directories, binary files, and files ignored by version control systems like Git (via .gitignore). It provides rich output formatting, including syntax highlighting and line numbers. Its performance is often attributed to its use of memory maps, specialized regex engines, and parallel directory traversal.
REGEX ENGINE
At its core, ripgrep utilizes Rust's highly optimized regex crate. This crate implements regular expressions using finite automata, which are extremely fast. For advanced regex features not supported by the default engine, `ripgrep` can optionally use the PCRE2 engine via the --pcre2 flag.
HISTORY
Ripgrep was created by Andrew Gallant (BurntSushi), a well-known contributor to the Rust ecosystem, and first released in 2016. Its primary goal was to provide a `grep`-like tool that was significantly faster than existing alternatives like `GNU grep`, `ack`, or `the_silver_searcher` (ag), while also being more user-friendly with sensible defaults. Written in Rust, it quickly gained popularity due to its impressive performance, often outperforming its predecessors by a considerable margin, and has become a standard tool in many developers' workflows.