ripgrep
Recursively search directories for a regex pattern
TLDR
View documentation for the original command
SYNOPSIS
rg [OPTIONS] PATTERN [PATH ...]
PARAMETERS
PATTERN
The regular expression to search for.
[PATH ...]
One or more paths to search. If no paths are specified, ripgrep searches the current directory.
-i, --ignore-case
Perform case-insensitive matching. By default, ripgrep performs case-sensitive matching.
-w, --word-regexp
Only match whole words. A word is defined as a sequence of Unicode letters, numbers, or underscores.
-n, --line-number
Show line numbers (starting from 1) with each match.
-H, --with-filename
Print the file name for each match.
-c, --count
Only print a count of matching lines for each file.
-v, --invert-match
Select non-matching lines.
-r, --replace
Replace every match with the given replacement string. This only outputs the results; it doesn't modify the files themselves.
-g, --glob
Include or exclude files for searching that match the given glob. Multiple globs can be specified.
-u, --unrestricted
Search normally hidden files and directories. Multiple -u's increase the level of unrestrictedness.
-l, --files-with-matches
Only print the names of files containing matches.
-L, --files-without-match
Only print the names of files not containing matches.
--context
Show
--color
Control whether to use colors. Possible values are 'never', 'auto', 'always', or 'ansi'.
--binary
Do not filter out binary files. Search all files, even if ripgrep thinks they are binary.
--hidden
Search hidden files and directories. By default, ripgrep ignores hidden files and directories.
--ignore-file
Specify a file path to read ignore patterns from.
Multiple ignore files can be specified.
DESCRIPTION
Ripgrep (rg) is a command-line tool that searches input files for a regular expression pattern.
It's designed to be faster than other popular search tools like grep, ack, and silver searcher, by leveraging Rust's performance and employing several optimizations. These include smart defaults such as automatically ignoring binary files and hidden directories specified in `.gitignore` files, using multithreading for parallelism, and employing literal string optimizations where possible. Ripgrep prioritizes usability and includes features such as support for various file encodings (UTF-8, UTF-16, etc.), prefilters that skip large swaths of files that couldn't possibly match, and the ability to search within compressed files. Because of its speed, smart defaults and extensive feature set, ripgrep is a valuable tool for developers and system administrators alike. It can be used to find specific code snippets, identify configuration settings, and analyze log files efficiently.
CAVEATS
Ripgrep relies on regular expressions for pattern matching. Understanding regular expression syntax is crucial for effective use. Large files may take longer to search, although ripgrep's optimizations generally mitigate this.
EXIT STATUS
Ripgrep exits with code 0 if one or more matches are found. It exits with 1 if no matches are found. It exits with 2 if there was an error.
PERFORMANCE CONSIDERATIONS
While ripgrep is generally very fast, performance can be affected by the complexity of the regular expression, the size of the files being searched, and the number of files to search. Using more specific patterns and limiting the search scope can improve performance.
Consider using `--files-with-matches` when you only need to know the files that match to improve performance.
HISTORY
Ripgrep was created by Andrew Gallant, with the first commit being on May 12, 2016.
It was designed to be a faster alternative to other popular grep-like tools.
The key motivation behind ripgrep's creation was to provide a highly performant search tool that leverages modern hardware and software features, such as multithreading and Rust's efficient memory management.
Since its initial release, ripgrep has gained significant popularity among developers and system administrators due to its speed, usability, and feature set.