ripgreb
Recursively search directories for a regex pattern
SYNOPSIS
rg [OPTIONS] PATTERN [PATH ...]
PARAMETERS
PATTERN
The regular expression to search for.
[PATH ...]
One or more paths to search. Defaults to the current directory if no path is provided.
-i, --ignore-case
Ignore case distinctions in the PATTERN.
-w, --word-regexp
Only match whole words.
-n, --line-number
Show line numbers.
-H, --with-filename
Print the file name for each match. This is the default behavior when searching multiple files.
-l, --files-with-matches
Only print the names of files containing matches, not the matching lines themselves.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-c, --count
Only print a count of matching lines for each input file.
-r, --replace REPLACEMENT_TEXT
Replace each match with REPLACEMENT_TEXT.
-g, --glob GLOB
Include files matching GLOB. May be provided multiple times.
-u, --unrestricted
Search hidden and ignored files/directories. Can be used multiple times to relax restrictions further.
--type-add TYPE_SPEC
Associate a file type with a glob. For example: --type-add 'foo:*.foo'
--type-clear
Clear all file type associations.
--files
Print each file that would be searched without actually searching.
--help
Show help message and exit.
--version
Show version information and exit.
DESCRIPTION
ripgrep is a line-oriented search tool that recursively searches directories for a regular expression pattern.
By default, ripgrep respects .gitignore rules and automatically skips hidden files/directories and binary files.
ripgrep boasts speed and efficiency, often outperforming other similar tools like grep, ag, and ack, especially when searching large codebases. Its intelligent defaults and configuration options make it a powerful and versatile tool for developers, system administrators, and anyone needing to quickly locate specific text within files.
It can also be used to replace text using the `-r` flag. It features include: Unicode support, searching specific file types, showing context around matches.
CAVEATS
ripgrep relies on regular expressions for pattern matching. Understanding regular expression syntax is crucial for effective use.
Using overly broad regular expressions can significantly impact performance.
While ripgrep attempts to handle various character encodings, unexpected behavior may occur with certain non-UTF-8 encoded files.
EXIT STATUS
ripgrep exits with code 0 if one or more matches are found, 1 if no matches are found, and any other code if an error occurred.
FILE ENCODING
ripgrep automatically detects UTF-8, UTF-16, and other common text encodings. For performance, UTF-8 is preferred. If an encoding cannot be reliably detected, ripgrep may treat the file as binary or search it using the default encoding of the system.
HISTORY
ripgrep was created by Andrew Gallant. It was first released in 2016 and quickly gained popularity due to its speed, efficiency, and intelligent defaults. ripgrep is written in Rust, which contributes to its performance and memory safety. It has become a widely adopted tool for code search and general-purpose text searching, replacing many traditional uses of grep in development workflows.