RG(1)
๐ rg โ ripgrep ๐
okay bestie, sit DOWN. this is rg(1), a User Commands manual page, and it's literally the search tool that will change your whole terminal life. no cap.
โจ NAME โจ
rg โ recursively search the current directory for lines matching a pattern. that's it. that's the whole vibe. ๐ฆ
๐ธ SYNOPSIS ๐ธ
rg [OPTIONS] PATTERN [PATH...]
rg [OPTIONS] -e PATTERN... [PATH...]
rg [OPTIONS] -f PATTERNFILE... [PATH...]
rg [OPTIONS] --files [PATH...]
rg [OPTIONS] --type-list
command | rg [OPTIONS] PATTERN
rg [OPTIONS] --help
rg [OPTIONS] --version
๐ DESCRIPTION ๐
so ripgrep (that's rg, her nickname, we're on a first-name basis) recursively searches the current directory for a regex pattern. and the way she does it? iconic. by default, ripgrep will respect your .gitignore and automatically skip hidden files/directories and binary files. she just knows. ๐
ripgrep's default regex engine uses finite automata and guarantees linear time searching. because of this, features like backreferences and arbitrary look-around are not supported. ๐ญ however, if ripgrep is built with PCRE2, then the -P/--pcre2 flag can be used to enable backreferences and look-around. slay, options!
ripgrep supports configuration files. set RIPGREP_CONFIG_PATH to a configuration file. the file can specify one shell argument per line. lines starting with # are ignored. for more details, see CONFIGURATION FILES below. ๐
ripgrep will automatically detect if stdin is a readable file and search stdin for a regex pattern, e.g. ls | rg foo. in some environments, stdin may exist when it shouldn't. to turn off stdin detection, one can explicitly specify the directory to search, e.g. rg foo ./. ๐
like other tools such as ls, ripgrep will alter its output depending on whether stdout is connected to a tty. by default, when printing a tty, ripgrep will enable colors, line numbers and a heading format that lists each matching file path once instead of once per matching line. main character formatting energy, honestly.
Tip: to disable all smart filtering and make ripgrep behave a bit more like classicalgrep, userg -uuu. ๐ซถ
๐ง REGEX SYNTAX ๐ง
ripgrep uses Rust's regex engine by default, which documents its syntax:
https://docs.rs/regex/1.*/regex/#syntax
ripgrep uses byte-oriented regexes, which has some additional documentation:
https://docs.rs/regex/1.*/regex/bytes/index.html#syntax
to a first approximation, ripgrep uses Perl-like regexes without look-around or backreferences. this makes them very similar to the "extended" (ERE) regular expressions supported by egrep, but with a few additional features like Unicode character classes. โจ
if you're using ripgrep with the -P/--pcre2 flag, then please consult https://www.pcre.org or the PCRE2 man pages for documentation on the supported syntax.
๐ POSITIONAL ARGUMENTS ๐
PATTERNโ a regular expression used for searching. to match a pattern beginning with a dash, use the-e/--regexpoption. (dash-first patterns are little divas, they need special handling ๐ )PATHโ a file or directory to search. directories are searched recursively. file paths specified explicitly on the command line override glob and ignore rules. so if you say it out loud, she listens. periodt.
๐ OPTIONS ๐
this section documents all flags that ripgrep accepts. flags are grouped into categories below according to their function.
note that many options can be turned on and off. in some cases, those flags are not listed explicitly below. for example, the --column flag (listed below) enables column numbers in ripgrep's output, but the --no-column flag (not listed below) disables them. the reverse can also exist. for example, the --no-ignore flag (listed below) disables ripgrep's gitignore logic, but the --ignore flag (not listed below) enables it. these flags are useful for overriding a ripgrep configuration file (or alias) on the command line. each flag's documentation notes whether an inverted flag exists. in all cases, the flag specified last takes precedence. last one wins, bestie, like always. ๐
๐ฅ INPUT OPTIONS ๐ฅ
-e PATTERN,--regexp=PATTERNโ a pattern to search for. this option can be provided multiple times, where all patterns given are searched, in addition to any patterns provided by-f/--file. lines matching at least one of the provided patterns are printed. this flag can also be used when searching for patterns that start with a dash. ๐
for example, to search for the literal -foo:
rg -e -foo
you can also use the special -- delimiter to indicate that no more flags will be provided. namely, the following is equivalent to the above:
rg -- -foo
when -f/--file or -e/--regexp is used, then ripgrep treats all positional arguments as files or directories to search.
-f PATTERNFILE,--file=PATTERNFILEโ search for patterns from the given file, with one pattern per line. when this flag is used multiple times or in combination with the-e/--regexpflag, then all patterns provided are searched. empty pattern lines will match all input lines, and the newline is not counted as part of the pattern. ๐
a line is printed if and only if it matches at least one of the patterns.
when PATTERNFILE is -, then stdin will be read for the patterns.
when -f/--file or -e/--regexp is used, then ripgrep treats all positional arguments as files or directories to search.
--pre=COMMANDโ for each inputPATH, this flag causes ripgrep to search the standard output ofCOMMAND PATHinstead of the contents ofPATH. this option expects theCOMMANDprogram to either be a path or to be available in yourPATH. either an empty stringCOMMANDor the--no-preflag will disable this behavior. ๐ฆ
WARNING โ when this flag is set, ripgrep will unconditionally spawn a process for every file that is searched. therefore, this can incur an unnecessarily large performance penalty if you don't otherwise need the flexibility offered by this flag. one possible mitigation to this is to use the --pre-glob flag to limit which files a preprocessor is run with. (bestie. every. single. file. ๐ญ)
a preprocessor is not run when ripgrep is searching stdin.
when searching over sets of files that may require one of several preprocessors, COMMAND should be a wrapper program which first classifies PATH based on magic numbers/content or based on the PATH name and then dispatches to an appropriate preprocessor. each COMMAND also has its standard input connected to PATH for convenience.
for example, a shell script for COMMAND might look like:
case "$1" in
*.pdf)
exec pdftotext "$1" -
;;
*)
case $(file "$1") in
*Zstandard*)
exec pzstd -cdq
;;
*)
exec cat
;;
esac
;;
esac
the above script uses pdftotext to convert a PDF file to plain text. for all other files, the script uses the file utility to sniff the type of the file based on its contents. if it is a compressed file in the Zstandard format, then pzstd is used to decompress the contents to stdout.
this overrides the -z/--search-zip flag.
--pre-glob=GLOBโ this flag works in conjunction with the--preflag. namely, when one or more--pre-globflags are given, then only files that match the given set of globs will be handed to the command specified by the--preflag. any non-matching files will be searched without using the preprocessor command. ๐ธ
this flag is useful when searching many files with the --pre flag. namely, it provides the ability to avoid process overhead for files that don't need preprocessing. for example, given the following shell script, pre-pdftotext:
#!/bin/sh
pdftotext "$1" -
then it is possible to use --pre pre-pdftotext --pre-glob '*.pdf' to make it so ripgrep only executes the pre-pdftotext command on files with a .pdf extension.
multiple --pre-glob flags may be used. globbing rules match gitignore globs. precede a glob with a ! to exclude it.
this flag has no effect if the --pre flag is not used.
-z,--search-zipโ this flag instructs ripgrep to search in compressed files. currentlygzip,bzip2,xz,LZ4,LZMA,BrotliandZstdfiles are supported. this option expects the decompression binaries (such asgzip) to be available in yourPATH. if the required binaries are not found, then ripgrep will not emit an error messages by default. use the--debugflag to see more information. ๐
note that this flag does not make ripgrep search archive formats as directory trees. it only makes ripgrep detect compressed files and then decompress them before searching their contents as it would any other file.
this overrides the --pre flag.
this flag can be disabled with --no-search-zip.
๐ SEARCH OPTIONS ๐
-s,--case-sensitiveโ execute the search case sensitively. this is the default mode.
this is a global option that applies to all patterns given to ripgrep. individual patterns can still be matched case insensitively by using inline regex flags. for example, (?i)abc will match abc case insensitively even when this flag is used.
this flag overrides the -i/--ignore-case and -S/--smart-case flags.
--crlfโ when enabled, ripgrep will treat CRLF (\r\n) as a line terminator instead of just\n. ๐ซถ
principally, this permits the line anchor assertions ^ and $ in regex patterns to treat CRLF, CR or LF as line terminators instead of just LF. note that they will never match between a CR and a LF. CRLF is treated as one single line terminator.
when using the default regex engine, CRLF support can also be enabled inside the pattern with the R flag. for example, (?R:$) will match just before either CR or LF, but never between CR and LF.
this flag overrides --null-data.
this flag can be disabled with --no-crlf.
--dfa-size-limit=NUM+SUFFIX?โ the upper size limit of the regex DFA. the default limit is something generous for any single pattern or for many smallish patterns. this should only be changed on very large regex inputs where the (slower) fallback regex engine may otherwise be used if the limit is reached. โญ
the input format accepts suffixes of K, M or G which correspond to kilobytes, megabytes and gigabytes, respectively. if no suffix is provided the input is treated as bytes.
-E ENCODING,--encoding=ENCODINGโ bestie, this one tells ripgrep which text encoding to use on every single file it searches. The default isauto, which makes ripgrep do a best-effort auto-detect of encoding on a per-file basis โจ. And ngl, that automatic detection is only for files that start with a UTF-8 or UTF-16 byte-order mark (BOM). No other automatic detection happens, periodt. You can also passnone, which completely disables BOM sniffing and just searches the raw bytes โ BOM included if it's there โ no matter what encoding it is ๐.
Other supported values live in the list of labels right here: https://encoding.spec.whatwg.org/#concept-encoding-get.
Want the whole deep dive on encoding and how ripgrep handles it? See GUIDE.md ๐.
And if you wanna snap the encoding detection back to its automatic mode, that's what --no-encoding is for, iykyk.
--engine=ENGINEโ pick which regular expression engine ripgrep uses. When you choose a regex engine, that choice applies to every regex you hand to ripgrep (like when you pass multiple-e/--regexpor-f/--fileflags) ๐.
Accepted values are default, pcre2, or auto.
The default value is default, which is usually the fastest and should be good for most use cases ๐
. The pcre2 engine is generally what you want when you need features like look-around or backreferences. And auto will dynamically choose between supported regex engines depending on the features used in a pattern, on a best-effort basis ๐ฆ.
Heads up: the pcre2 engine is an optional ripgrep feature. If PCRE2 wasn't included in your build of ripgrep, using this flag will make ripgrep print an error message and exit ๐ญ.
This overrides previous uses of the -P/--pcre2 and --auto-hybrid-regex flags.
-F,--fixed-stringsโ treat all patterns as literals instead of as regular expressions. So when this flag is on, special regex meta characters like.(){}*+should not need to be escaped ๐ธ.
You can turn this off with --no-fixed-strings.
-i,--ignore-caseโ when this flag shows up, all patterns get searched case insensitively ๐. The case insensitivity rules used by ripgrep's default regex engine conform to Unicode's "simple" case folding rules.
This is a global option โ it applies to all patterns you give ripgrep. But individual patterns can still be matched case sensitively by using inline regex flags. For example, (?-i)abc will match abc case sensitively even when this flag is used โจ.
This flag overrides -s/--case-sensitive and -S/--smart-case.
-v,--invert-matchโ this flag inverts matching ๐. So instead of printing the lines that match, ripgrep prints the lines that don't match.
Note that this only inverts line-by-line matching. For example, combining this flag with -l/--files-with-matches will emit files that contain any lines that do not match the patterns given. That's not the same as, say, --files-without-match, which emits files that don't contain any matching lines ๐.
You can turn this off with --no-invert-match.
-x,--line-regexpโ when enabled, ripgrep only shows matches that are surrounded by line boundaries. This is equivalent to wrapping every pattern in^and$. In other words, it only prints lines where the entire line participates in a match ๐.
This overrides the -w/--word-regexp flag.
-m NUM,--max-count=NUMโ cap the number of matching lines per file searched atNUM๐.
When -U/--multiline is used, a single match that spans multiple lines is only counted once for the purposes of this limit. And multiple matches on a single line are counted only once too, same as they would be in non-multiline mode ๐
.
When you combine this with -A/--after-context or -C/--context, it's possible for more matches than the maximum to be printed if the contextual lines happen to contain a match. So like, don't be shocked, it's not a bug bestie.
Note that 0 is a legal value but it's probably not gonna be useful. When it's used, ripgrep won't search anything ๐ซถ.
--mmapโ when enabled, ripgrep searches using memory maps when it can. This is enabled by default when ripgrep thinks it'll be faster โญ.
Memory map searching can't be used in all circumstances though. For example, when searching virtual files or streams like stdin. In those cases, memory maps won't be used even when this flag is enabled.
Careful bestie: ripgrep may abort unexpectedly when memory maps are used, if it searches a file that is simultaneously truncated. If you wanna opt out of that possibility, just disable memory maps ๐ญ.
You can turn this off with --no-mmap.
-U,--multilineโ this flag enables searching across multiple lines โจ.
When multiline mode is on, ripgrep lifts the restriction that a match can't include a line terminator. For example, when multiline mode is not enabled (which is the default), the regex \p{any} will match any Unicode codepoint other than \n. Similarly, the regex \n is explicitly forbidden, and if you try to use it, ripgrep returns an error ๐. But when multiline mode is enabled, \p{any} will match any Unicode codepoint, including \n, and regexes like \n are permitted ๐ฆ.
An important caveat: multiline mode does not change the match semantics of .. Namely, in most regex matchers, a . will by default match any character other than \n, and that's true in ripgrep as well. To make . match \n, you have to enable the "dot all" flag inside the regex. For example, both (?s). and (?s:.) have the same semantics, where . will match any character, including \n. Alternatively, the --multiline-dotall flag can be passed to make the "dot all" behavior the default. This flag only applies when multiline search is enabled ๐.
There is no limit on the number of lines that a single match can span ๐.
WARNING: Because of how the underlying regex engine works, multiline searches may be slower than normal line-oriented searches, and they may also use more memory. In particular, when multiline mode is enabled, ripgrep requires that each file it searches is laid out contiguously in memory (either by reading it onto the heap or by memory-mapping it). Things that can't be memory-mapped (likestdin) will be consumed until EOF before searching can even begin ๐ญ. In general, ripgrep will only do these things when necessary. Specifically, if the-U/--multilineflag is provided but the regex doesn't contain patterns that would match\ncharacters, then ripgrep will automatically avoid reading each file into memory before searching it. Nevertheless, if you only care about matches spanning at most one line, then it's always better to disable multiline mode. Periodt.
This overrides the --stop-on-nonmatch flag.
You can turn this off with --no-multiline.
--multiline-dotallโ this flag enables "dot all" mode in all regex patterns. This makes.match line terminators when multiline searching is enabled. It has no effect if multiline searching isn't enabled with the-U/--multilineflag ๐.
Normally, a . matches any character except line terminators. While this behavior typically isn't relevant for line-oriented matching (since matches can span at most one line), it can be useful when searching with the -U/--multiline flag. By default, multiline mode runs without "dot all" mode enabled โจ.
This flag is generally intended to be used in an alias or your ripgrep config file if you prefer "dot all" semantics by default ๐
. Note that regardless of whether this flag is used, "dot all" semantics can still be controlled via inline flags in the regex pattern itself โ e.g., (?s:.) always enables "dot all" whereas (?-s:.) always disables "dot all". Plus, you can use character classes like \p{any} to match any Unicode codepoint regardless of whether "dot all" mode is enabled or not ๐ธ.
You can turn this off with --no-multiline-dotall.
--no-unicodeโ this flag disables Unicode mode for all patterns given to ripgrep ๐.
By default, ripgrep enables "Unicode mode" in all of its regexes. This has a bunch of consequences:
.will only match valid UTF-8 encoded Unicode scalar values.- Classes like
\w,\s,\dare all Unicode aware and much bigger than their ASCII-only versions. - Case insensitive matching will use Unicode case folding.
- A huge array of classes like
\p{Emoji}are available. (Although the specific set of classes available varies based on the regex engine. In general, the default regex engine has more classes available to it ๐.) - Word boundaries (
\band\B) use the Unicode definition of a word character.
In some cases it can be desirable to turn these things off, and this flag does exactly that ๐ฆ. For example, Unicode mode can sometimes have a negative impact on performance, especially when things like \w are used frequently (including via bounded repetitions like \w{100}) when only their ASCII interpretation is needed.
You can turn this off with --unicode.
--null-dataโ enabling this flag makes ripgrep use NUL as a line terminator instead of the default\n๐.
This is useful when searching large binary files that would otherwise have super long lines if \n were used as the line terminator. In particular, ripgrep requires that, at a minimum, each line must fit into memory. Using NUL instead can be a useful stopgap to keep memory requirements low and avoid OOM (out of memory) conditions ๐.
This is also useful for processing NUL delimited data, like what gets emitted when using ripgrep's -0/--null flag or find's --print0 flag โจ.
Using this flag implies -a/--text. It also overrides --crlf.
-P,--pcre2โ when this flag is present, ripgrep uses the PCRE2 regex engine instead of its default regex engine ๐ .
This is generally useful when you want to use features like look-around or backreferences.
Using this flag is the same as passing --engine=pcre2. Users may instead elect to use --engine=auto to ask ripgrep to automatically select the right regex engine based on the patterns given. This flag and the --engine flag override one another ๐ซถ.
Note that PCRE2 is an optional ripgrep feature, bestie. If PCRE2 wasn't included in your build of ripgrep, then using this flag will result in ripgrep printing an error message and exiting. PCRE2 may also have worse user experience in some cases, since it has fewer introspection APIs than ripgrep's default regex engine. For example, if you use a \n in a PCRE2 regex without the -U/--multiline flag, then ripgrep will silently fail to match anything instead of reporting an error immediately (like it does with the default regex engine). Not the silent treatment bestie ๐ญ
This flag can be disabled with --no-pcre2.
--regex-size-limit=NUM+SUFFIX?โ the size limit of the compiled regex, where the compiled regex generally corresponds to a single object in memory that can match all of the patterns provided to ripgrep. The default limit is generous enough that most reasonable patterns (or even a small number of them) should fit. ๐ซถ
This is useful to change when you explicitly want to let ripgrep spend potentially much more time and/or memory building a regex matcher. Go big or go home, right? ๐
The input format accepts suffixes of K, M or G which correspond to kilobytes, megabytes and gigabytes, respectively. If no suffix is provided the input is treated as bytes.
-S,--smart-caseโ this flag instructs ripgrep to search case insensitively if the pattern is all lowercase. Otherwise, ripgrep will search case sensitively.
A pattern is considered all lowercase if both of the following rules hold:
- First, the pattern contains at least one literal character. For example,
a\wcontains a literal (a) but just\wdoes not. - Second, of the literals in the pattern, none of them are considered to be uppercase according to Unicode. For example,
foo\pLhas no uppercase literals butFoo\pLdoes.
This overrides the -s/--case-sensitive and -i/--ignore-case flags. It's giving "read the room" energy fr fr โจ
--stop-on-nonmatchโ enabling this option will cause ripgrep to stop reading a file once it encounters a non-matching line after it has encountered a matching line. This is useful if it is expected that all matches in a given file will be on sequential lines, for example due to the lines being sorted. ๐
This overrides the -U/--multiline flag.
-a,--textโ this flag instructs ripgrep to search binary files as if they were text. When this flag is present, ripgrep's binary file detection is disabled. This means that when a binary file is searched, its contents may be printed if there is a match. This may cause escape codes to be printed that alter the behavior of your terminal. ๐ณ
When binary file detection is enabled, it is imperfect. In general, it uses a simple heuristic. If a NUL byte is seen during search, then the file is considered binary and searching stops (unless this flag is present). Alternatively, if the --binary flag is used, then ripgrep will only quit when it sees a NUL byte after it sees a match (or searches the entire file).
This flag overrides the --binary flag.
This flag can be disabled with --no-text.
-j NUM,--threads=NUMโ this flag sets the approximate number of threads to use. A value of0(which is the default) causes ripgrep to choose the thread count using heuristics. Let it cook ๐ฅ-w,--word-regexpโ when enabled, ripgrep will only show matches surrounded by word boundaries. This is equivalent to surrounding every pattern with\b{start-half}and\b{end-half}. These are a custom syntax from ripgrep's default regex engine that, unlike\b, doesn't require matching a word character on one side. That is,\b{start-half}corresponds to matching\W|\Aon the left and\b{end-half}corresponds to matching\W|\zon the right. ๐
This overrides the -x/--line-regexp flag.
--auto-hybrid-regexโ DEPRECATED. Use--engineinstead. ๐ฉ
When this flag is used, ripgrep will dynamically choose between supported regex engines depending on the features used in a pattern. When ripgrep chooses a regex engine, it applies that choice for every regex provided to ripgrep (e.g., via multiple -e/--regexp or -f/--file flags).
As an example of how this flag might behave, ripgrep will attempt to use its default finite automata based regex engine whenever the pattern can be successfully compiled with that regex engine. If PCRE2 is enabled and if the pattern given could not be compiled with the default regex engine, then PCRE2 will be automatically used for searching. If PCRE2 isn't available, then this flag has no effect because there is only one regex engine to choose from.
In the future, ripgrep may adjust its heuristics for how it decides which regex engine to use. In general, the heuristics will be limited to a static analysis of the patterns, and not to any specific runtime behavior observed while searching files.
The primary downside of using this flag is that it may not always be obvious which regex engine ripgrep uses, and thus, the match semantics or performance profile of ripgrep may subtly and unexpectedly change. However, in many cases, all regex engines will agree on what constitutes a match and it can be nice to transparently support more advanced regex features like look-around and backreferences without explicitly needing to enable them. ๐
This flag can be disabled with --no-auto-hybrid-regex.
--no-pcre2-unicodeโ DEPRECATED. Use--no-unicodeinstead. ๐ฉ
Note that Unicode mode is enabled by default.
This flag can be disabled with --pcre2-unicode.
๐ธ FILTER OPTIONS ๐ธ
--binaryโ enabling this flag will cause ripgrep to search binary files. By default, ripgrep attempts to automatically skip binary files in order to improve the relevance of results and make the search faster. ๐ฆ
Binary files are heuristically detected based on whether they contain a NUL byte or not. By default (without this flag set), once a NUL byte is seen, ripgrep will stop searching the file. Usually, NUL bytes occur in the beginning of most binary files. If a NUL byte occurs after a match, then ripgrep will not print the match, stop searching that file, and emit a warning that some matches are being suppressed. ๐
In contrast, when this flag is provided, ripgrep will continue searching a file even if a NUL byte is found. In particular, if a NUL byte is found then ripgrep will continue searching until either a match is found or the end of the file is reached, whichever comes sooner. If a match is found, then ripgrep will stop and print a warning saying that the search stopped prematurely.
If you want ripgrep to search a file without any special NUL byte handling at all (and potentially print binary data to stdout), then you should use the -a/--text flag.
The --binary flag is a flag for controlling ripgrep's automatic filtering mechanism. As such, it does not need to be used when searching a file explicitly or when searching stdin. That is, it is only applicable when recursively searching a directory.
When the -u/--unrestricted flag is provided for a third time, then this flag is automatically enabled.
This flag overrides the -a/--text flag.
This flag can be disabled with --no-binary.
-L,--followโ this flag instructs ripgrep to follow symbolic links while traversing directories. This behavior is disabled by default. Note that ripgrep will check for symbolic link loops and report errors if it finds one. ripgrep will also report errors for broken links. To suppress error messages, use the--no-messagesflag. ๐
This flag can be disabled with --no-follow.
-g GLOB,--glob=GLOBโ include or exclude files and directories for searching that match the given glob. This always overrides any other ignore logic. Multiple glob flags may be used. Globbing rules match.gitignoreglobs. Precede a glob with a!to exclude it. If multiple globs match a file or directory, the glob given later in the command line takes precedence. โจ
As an extension, globs support specifying alternatives: -g 'ab{c,d}*' is equivalent to -g abc -g abd. Empty alternatives like -g 'ab{,c}' are not currently supported. Note that this syntax extension is also currently enabled in gitignore files, even though this syntax isn't supported by git itself. ripgrep may disable this syntax extension in gitignore files, but it will always remain available via the -g/--glob flag.
When this flag is set, every file and directory is applied to it to test for a match. For example, if you only want to search in a particular directory foo, then -g foo is incorrect because foo/bar does not match the glob foo. Instead, you should use -g 'foo/**'. Bestie the glob has to actually match the path, ok? ๐ญ
--glob-case-insensitiveโ process all glob patterns given with the-g/--globflag case insensitively. This effectively treats-g/--globas--iglob. ๐
This flag can be disabled with --no-glob-case-insensitive.
-.,--hiddenโ search hidden files and directories. By default, hidden files and directories are skipped. Note that if a hidden file or a directory is whitelisted in an ignore file, then it will be searched even if this flag isn't provided. Similarly if a hidden file or directory is given explicitly as an argument to ripgrep. ๐ซฃ
A file or directory is considered hidden if its base name starts with a dot character (.). On operating systems which support a "hidden" file attribute, like Windows, files with this attribute are also considered hidden.
Note that -./--hidden will include files and folders like .git regardless of --no-ignore-vcs. To exclude such paths when using -./--hidden, you must explicitly ignore them using another flag or ignore file.
This flag can be disabled with --no-hidden.
--iglob=GLOBโ include or exclude files and directories for searching that match the given glob. This always overrides any other ignore logic. Multiple glob flags may be used. Globbing rules match.gitignoreglobs. Precede a glob with a!to exclude it. If multiple globs match a file or directory, the glob given later in the command line takes precedence. Globs used via this flag are matched case insensitively. ๐--ignore-file=PATHโ bestie, this one hands ripgrep a path to one or more gitignore-formatted rules files. Where do those patterns land in the pecking order? They get applied after whatever's in.gitignore,.rgignoreand.ignore, and they're matched relative to the current working directory. So basically: files you name with this flag have lower precedence than the ones ripgrep finds automatically in the directory tree. Wanna stack multiple extra ignore files? Just repeat the flag. And when you do specify several, the earlier files have lower precedence than the later ones. ๐ซถ
Oh and heads up โ if what you actually want is to include or exclude files and directories directly on the command line, then go use -g/--glob instead. That's the move. ๐
--ignore-file-case-insensitiveโ process ignore files (.gitignore,.ignore, etc.) case insensitively. Fair warning bestie: this comes with a performance penalty, and it's most useful on case insensitive file systems (such as Windows).
This flag can be disabled with --no-ignore-file-case-insensitive.
-d NUM,--max-depth=NUMโ caps how deep ripgrep will go, limiting directory traversal to NUM levels beyond the paths you gave it. A value of0means it only searches the explicitly given paths themselves. ๐
For example, rg --max-depth 0 dir/ is a no-op because dir/ will not be descended into. And rg --max-depth 1 dir/ will search only the direct children of dir.
There's an alternative spelling too: --maxdepth.
--max-filesize=NUM+SUFFIX?โ ignore files bigger than NUM in size. This does not apply to directories, just files.
The input format accepts suffixes of K, M or G, which correspond to kilobytes, megabytes and gigabytes, respectively. If you don't give a suffix, the input is treated as bytes.
Examples: --max-filesize 50K or --max-filesize 80M. โจ
--no-ignoreโ when set, ignore files such as.gitignore,.ignoreand.rgignorewill not be respected. This implies--no-ignore-dot,--no-ignore-exclude,--no-ignore-global,--no-ignore-parentand--no-ignore-vcs.
It does not imply --no-ignore-files, since --ignore-file is specified explicitly as a command line argument. iykyk.
When given only once, the -u/--unrestricted flag is identical in behavior to this flag and can be considered an alias. But โ plot twist โ subsequent -u/--unrestricted flags have additional effects. ๐
This flag can be disabled with --ignore.
--no-ignore-dotโ don't respect filter rules from.ignoreor.rgignorefiles.
This does not impact whether ripgrep will ignore files and directories whose names begin with a dot. For that, see the -./--hidden flag. This flag also does not impact whether filter rules from .gitignore files are respected.
This flag can be disabled with --ignore-dot.
--no-ignore-excludeโ don't respect filter rules from files that are manually configured for the repository. For example, this includes git's.git/info/exclude.
This flag can be disabled with --ignore-exclude.
--no-ignore-filesโ when set, any--ignore-fileflags, even ones that come after this flag, are ignored. Yeah, even the later ones. No exceptions, bestie.
This flag can be disabled with --ignore-files.
--no-ignore-globalโ don't respect filter rules from ignore files that come from "global" sources such as git'score.excludesFileconfiguration option (which defaults to$HOME/.config/git/ignore).
This flag can be disabled with --ignore-global.
--no-ignore-parentโ when this flag is set, filter rules from ignore files found in parent directories are not respected. By default, ripgrep will ascend the parent directories of the current working directory to look for any applicable ignore files that should be applied. In some cases this may not be desirable. ๐คทโโ๏ธ
This flag can be disabled with --ignore-parent.
--no-ignore-vcsโ when given, filter rules from source control ignore files (e.g.,.gitignore) are not respected. By default, ripgrep respects git's ignore rules for automatic filtering. In some cases, it may not be desirable to respect the source control's ignore rules and instead only respect rules in.ignoreor.rgignore.
Note that this flag does not directly affect the filtering of source control files or folders that start with a dot (.), like .git. Those are affected by -./--hidden and its related flags instead.
This flag implies --no-ignore-parent for source control ignore files as well.
This flag can be disabled with --ignore-vcs.
--no-require-gitโ when this flag is given, source control ignore files such as.gitignoreare respected even if no git repository is present. ๐ฆ
By default, ripgrep will only respect filter rules from source control ignore files when ripgrep detects that the search is executed inside a source control repository. For example, when a .git directory is observed.
This flag relaxes the default restriction. For example, it might be useful when the contents of a git repository are stored or copied somewhere, but where the repository state is absent.
This flag can be disabled with --require-git.
--one-file-systemโ when enabled, ripgrep will not cross file system boundaries relative to where the search started from.
Note that this applies to each path argument given to ripgrep. For example, in the command
rg --one-file-system /foo/bar /quux/baz
ripgrep will search both /foo/bar and /quux/baz even if they are on different file systems, but will not cross a file system boundary when traversing each path's directory tree. ๐
This is similar to find's -xdev or -mount flag.
This flag can be disabled with --no-one-file-system.
-t TYPE,--type=TYPEโ this flag limits ripgrep to searching files matching TYPE. Multiple-t/--typeflags may be provided. ๐
This flag supports the special value all, which will behave as if -t/--type was provided for every file type supported by ripgrep (including any custom file types). The end result is that --type=all causes ripgrep to search in "whitelist" mode, where it will only search files it recognizes via its type definitions.
Note that this flag has lower precedence than both the -g/--glob flag and any rules found in ignore files.
To see the list of available file types, use the --type-list flag. โจ
-T TYPE,--type-not=TYPEโ do not search files matching TYPE. Multiple-T/--type-notflags may be provided. Use the--type-listflag to list all available types.
This flag supports the special value all, which will behave as if -T/--type-not was provided for every file type supported by ripgrep (including any custom file types). The end result is that --type-not=all causes ripgrep to search in "blacklist" mode, where it will only search files that are unrecognized by its type definitions.
To see the list of available file types, use the --type-list flag.
--type-add=TYPESPECโ this flag adds a new glob for a particular file type. Only one glob can be added at a time. Multiple--type-addflags can be provided. Unless--type-clearis used, globs are added to any existing globs defined inside of ripgrep.
Note that this must be passed to every invocation of ripgrep. Type settings are not persisted. See CONFIGURATION FILES for a workaround.
Example:
rg --type-add 'foo:*.foo' -tfoo PATTERN
This flag can also be used to include rules from other types with the special include directive. The include directive permits specifying one or more other type names (separated by a comma) that have been defined and its rules will automatically be imported into the type specified. For example, to create a type called src that matches C++, Python and Markdown files, one can use:
--type-add 'src:include:cpp,py,md'
Additional glob rules can still be added to the src type by using this flag again:
--type-add 'src:include:cpp,py,md' --type-add 'src:*.foo'
Note that type names must consist only of Unicode letters or numbers. Punctuation characters are not allowed. ๐
--type-clear=TYPEโ clear the file type globs previously defined for TYPE. This clears any previously defined globs for the TYPE, but globs can be added after this flag.
Note that this must be passed to every invocation of ripgrep. Type settings are not persisted. See CONFIGURATION FILES for a workaround.
-u,--unrestrictedโ this flag reduces the level of "smart" filtering. Repeated uses (up to 3) reduces the filtering even more. When repeated three times, ripgrep will search every file in a directory tree. ๐ค
A single -u/--unrestricted flag is equivalent to --no-ignore. Two -u/--unrestricted flags is equivalent to --no-ignore -./--hidden. Three -u/--unrestricted flags is equivalent to --no-ignore -./--hidden --binary.
The only filtering ripgrep still does when -uuu is given is to skip symbolic links and to avoid printing matches from binary files. Symbolic links can be followed via the -L/--follow flag, and binary files can be treated as text files via the -a/--text flag. ๐ซถ
๐ OUTPUT OPTIONS ๐
-A NUM,--after-context=NUMโ show NUM lines after each match.
This overrides the --passthru flag and partially overrides the -C/--context flag.
-B NUM,--before-context=NUMโ show NUM lines before each match.
This overrides the --passthru flag and partially overrides the -C/--context flag.
--block-bufferedโ when enabled, ripgrep will use block buffering. That is, whenever a matching line is found, it will be written to an in-memory buffer and will not be written to stdout until the buffer reaches a certain size. This is the default when ripgrep's stdout is redirected to a pipeline or a file. When ripgrep's stdout is connected to a tty, line buffering will be used by default. Forcing block buffering can be useful when dumping a large amount of contents to a tty. ๐
This overrides the --line-buffered flag.
This flag can be disabled with --no-block-buffered.
-b,--byte-offsetโ print the 0-based byte offset within the input file before each line of output. If-o/--only-matchingis specified, print the offset of the matched text itself.
If ripgrep does transcoding, then the byte offset is in terms of the result of transcoding and not the original data. This applies similarly to other transformations on the data, such as decompression or a --pre filter. ๐ง
This flag can be disabled with --no-byte-offset.
๐จ --color=WHEN
Okay bestie, this one controls when ripgrep busts out the colors. The default is auto, which means ripgrep is gonna try to guess. Like, if it's printing to a tty? Colors on, slay. But if it's redirected to a file or a pipe? Colors suppressed, sorry babe. ๐
And ngl, ripgrep suppresses color output by default in some other situations too. These include, but are not limited to:
- When the
TERMenvironment variable is not set or set todumb. - When the
NO_COLORenvironment variable is set (regardless of value โ it just being there is enough, periodt). - When flags that imply there's no use for colors are given. Like, for example,
--vimgrepand--json.
The possible values for this flag are:
neverโ Colors will never be used. Ever. Not once. ๐ซautoโ The default. ripgrep tries to be smart about it. ๐งalwaysโ Colors will always be used regardless of where the output is sent.ansiโ Likealways, but it emits ANSI escapes (even in a Windows console). โจ
This flag also controls whether hyperlinks get emitted. For example, when a hyperlink format is specified, hyperlinks won't be used when color is suppressed. So if you want hyperlinks but no colors, you have to use the --colors flag to manually set all color styles to none:
--colors 'path:none' \
--colors 'line:none' \
--colors 'column:none' \
--colors 'match:none' \
--colors 'highlight:none'
๐ --colors=COLOR_SPEC
This flag specifies color settings for use in the output. You can pass it multiple times, and the settings get applied iteratively. Pre-existing color labels are limited to one of eight choices: red, blue, green, cyan, magenta, yellow, white and black. Styles are limited to nobold, bold, nointense, intense, nounderline, underline, noitalic or italic.
The format of the flag is {type}:{attribute}:{value}. So type should be one of path, line, column, highlight or match. attribute can be fg, bg or style. And value is either a color (for fg and bg) or a text style. There's also a special format, {type}:none, that will clear all color settings for type. ๐งผ
For example, this command changes the match color to magenta and the background color for line numbers to yellow:
rg --colors 'match:fg:magenta' --colors 'line:bg:yellow'
Another example โ this one will "highlight" the non-matching text in matching lines:
rg --colors 'highlight:bg:yellow' --colors 'highlight:fg:black'
The "highlight" color type is particularly useful for contrasting matching lines with the surrounding context that gets printed by the -B/--before-context, -A/--after-context, -C/--context or --passthru flags. Iconic combo fr. ๐ฅ
Extended colors can be used for value when the tty supports ANSI color sequences. These are specified as either x (256-color) or x,x,x (24-bit truecolor) where x is a number between 0 and 255 inclusive. And x may be given as a normal decimal number or a hexadecimal number, which is prefixed by 0x.
For example, this command changes the match background color to the one represented by the rgb value (0,128,255):
rg --colors 'match:bg:0,128,255'
or, equivalently,
rg --colors 'match:bg:0x0,0x80,0xFF'
Heads up bestie: theintenseandnointensestyles will have no effect when used alongside these extended color codes. They just do nothing. ๐
๐ --column
Show column numbers (1-based). This only shows the column numbers for the first match on each line. And no, it does not try to account for Unicode โ one byte is equal to one column, periodt. This implies -n/--line-number.
When -o/--only-matching is used, then the column numbers written correspond to the start of each match. ๐ฏ
This flag can be disabled with --no-column.
๐ซถ -C NUM, --context=NUM
Show NUM lines before and after each match. This is equivalent to providing both the -B/--before-context and -A/--after-context flags with the same value. Two-for-one, we love efficiency. โจ
This overrides the --passthru flag. The -A/--after-context and -B/--before-context flags both partially override this flag, regardless of the order. For example, -A2 -C1 is equivalent to -A2 -B1.
โ๏ธ --context-separator=SEPARATOR
The string used to separate non-contiguous context lines in the output. This is only used when one of the context flags is used (that is, -A/--after-context, -B/--before-context or -C/--context). Escape sequences like \x7F or \t may be used. The default value is --.
When the context separator is set to an empty string, then a line break is still inserted. And if you want to completely disable context separators, use the --no-context-separator flag.
๐งฉ --field-context-separator=SEPARATOR
Set the field context separator. This separator is only used when printing contextual lines. It's used to delimit file paths, line numbers, columns and the contextual line itself. The separator may be any number of bytes, including zero. Escape sequences like \x7F or \t may be used.
The - character is the default value.
๐ --field-match-separator=SEPARATOR
Set the field match separator. This separator is only used when printing matching lines. It's used to delimit file paths, line numbers, columns and the matching line itself. The separator may be any number of bytes, including zero. Escape sequences like \x7F or \t may be used.
The : character is the default value.
๐ --heading
This flag prints the file path above clusters of matches from each file, instead of printing the file path as a prefix for each matched line. So much cleaner, honestly. ๐
This is the default mode when printing to a tty.
When stdout is not a tty, then ripgrep will default to the standard grep-like format. One can force this format in Unix-like environments by piping the output of ripgrep to cat. For example, rg foo | cat.
This flag can be disabled with --no-heading.
โ -h, --help
This flag prints the help output for ripgrep.
Unlike most other flags, the behavior of the short flag, -h, and the long flag, --help, is different. The short flag will show a condensed help output, while the long flag will show a verbose help output. The verbose help output has complete documentation, whereas the condensed help output will show only a single line for every flag. So if you're confused, go long, bestie. ๐ซถ
๐ฅ๏ธ --hostname-bin=COMMAND
This flag controls how ripgrep determines this system's hostname. The flag's value should correspond to an executable (either a path or something that can be found via your system's PATH environment variable). When set, ripgrep will run this executable, with no arguments, and treat its output (with leading and trailing whitespace stripped) as your system's hostname.
When not set (the default, or the empty string), ripgrep will try to automatically detect your system's hostname. On Unix, this corresponds to calling gethostname. On Windows, this corresponds to calling GetComputerNameExW to fetch the system's "physical DNS hostname."
ripgrep uses your system's hostname for producing hyperlinks. ๐
๐ฆ --hyperlink-format=FORMAT
Set the format of hyperlinks to use when printing results. Hyperlinks make certain elements of ripgrep's output, such as file paths, clickable. This generally only works in terminal emulators that support OSC-8 hyperlinks. For example, the format file://{host}{path} will emit an RFC 8089 hyperlink. To see the format that ripgrep is using, pass the --debug flag. ๐
Alternatively, a format string may correspond to one of the following aliases: default, none, cursor, file, grep+, kitty, macvim, textmate, vscode, vscode-insiders, vscodium. The alias will be replaced with a format string that is intended to work for the corresponding application.
The following variables are available in the format string:
{path}โ Required. This is replaced with a path to a matching file. The path is guaranteed to be absolute and percent encoded such that it is valid to put into a URI. Note that a path is guaranteed to start with a/.{host}โ Optional. This is replaced with your system's hostname. On Unix, this corresponds to callinggethostname. On Windows, this corresponds to callingGetComputerNameExWto fetch the system's "physical DNS hostname." Alternatively, if--hostname-binwas provided, then the hostname returned from the output of that program will be returned. If no hostname could be found, then this variable is replaced with the empty string.{line}โ Optional. If appropriate, this is replaced with the line number of a match. If no line number is available (for example, if--no-line-numberwas given), then it is automatically replaced with the value1.{column}โ Optional, but requires the presence of{line}. If appropriate, this is replaced with the column number of a match. If no column number is available (for example, if--no-columnwas given), then it is automatically replaced with the value1.{wslprefix}โ Optional. This is a special value that is set towsl$/WSL_DISTRO_NAME, whereWSL_DISTRO_NAMEcorresponds to the value of the equivalent environment variable. If the system is not Unix or if theWSL_DISTRO_NAMEenvironment variable is not set, then this is replaced with the empty string.
A format string may be empty. An empty format string is equivalent to the none alias. In this case, hyperlinks will be disabled.
At present, ripgrep does not enable hyperlinks by default. Users must opt into them. If you aren't sure what format to use, try default. ๐
Like colors, when ripgrep detects that stdout is not connected to a tty, then hyperlinks are automatically disabled, regardless of the value of this flag. Users can pass --color=always to forcefully emit hyperlinks.
Note that hyperlinks are only written when a path is also in the output and colors are enabled. To write hyperlinks without colors, you'll need to configure ripgrep to not colorize anything without actually disabling all ANSI escape codes completely:
--colors 'path:none' \
--colors 'line:none' \
--colors 'column:none' \
--colors 'match:none'
okay so why does it work like that?? because ripgrep treats the --color flag as a proxy for whether ANSI escape codes get used at all. which means env vars like NO_COLOR=1 and TERM=dumb don't just kill your colors, bestie โ they take your hyperlinks down with them ๐ญ same deal when ripgrep isn't writing to a tty. (Unless you force the issue with --color=always, main character style ๐
)
If you're searching a file directly, like:
rg foo path/to/file
then no hyperlinks for you, because the path you gave doesn't show up in the output at all. want the path to appear (and therefore a hyperlink too)? use the -H/--with-filename flag ๐ซถ
wanna go deeper on hyperlinks in terminal emulators? here's the lore:
https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
๐ธ still in OPTIONS, we're so back ๐ธ
--include-zeroโ when you pair this with-c/--countor--count-matches, ripgrep prints the number of matches for every file, even the ones with zero matches. it's disabled by default, but flip it on if you want ripgrep to act more like grep ๐
you can turn it back off with --no-include-zero.
--line-bufferedโ turn this on and ripgrep always uses line buffering. translation: the moment a matching line shows up, it gets flushed to stdout immediately. that's already the default when ripgrep's stdout is hooked to a tty, but otherwise ripgrep uses block buffering, which is typically faster. this flag forces line buffering even when it'd normally block-buffer. super handy in shell pipelines, like:
tail -f something.log | rg foo --line-buffered | rg bar
this overrides--block-buffered. you can turn it off with--no-line-buffered.
-n,--line-numberโ show line numbers (1-based) โจ
this is on by default when stdout is connected to a tty. you can turn it off with -N/--no-line-number.
-N,--no-line-numberโ suppress those line numbers, periodt.
line numbers are off by default when stdout is not connected to a tty. you can force them back on with -n/--line-number.
-M NUM,--max-columns=NUMโ give this a number and ripgrep will omit any line longer than that limit (in bytes, bestie, bytes). instead of dumping the long line, it just prints the number of matches in that line ๐
when this flag is left out or set to 0, it does absolutely nothing.
--max-columns-previewโ prints a little preview for lines that blow past your max column limit ๐
with-M/--max-columns, ripgrep by default fully replaces any too-long line with a message saying a matching line got removed. combine this flag with-M/--max-columnsand instead you get a preview of the line (up to the limit size), with the part exceeding the limit not shown. if-M/--max-columnsisn't set, this has no effect. you can turn it off with--no-max-columns-preview.
-0,--nullโ whenever a file path gets printed, slap a NUL byte right after it ๐ that covers printing file paths before matches, plus printing lists of matching files like with-c/--count,-l/--files-with-matchesand--files. chef's kiss withxargs.-o,--only-matchingโ print only the matched (non-empty) parts of a matching line, and each one gets its own separate output line โจ--path-separator=SEPARATORโ sets the path separator ripgrep uses when printing file paths. defaults to whatever your platform uses:/on Unix and\on Windows. this flag exists for when your environment demands an override (e.g., cygwin). a path separator is limited to a single byte ๐
setting this to an empty string reverts it to default behavior โ meaning the path separator gets auto-chosen based on your environment.
--passthruโ print matching and non-matching lines, both ๐ซถ
another way to get basically the same effect: modify your pattern to match the empty string. so if you're searching withrg foo, then usingrg '^|foo'instead emits every line in every file searched, but only the occurrences offooget highlighted. this flag does that same thing without you touching your pattern. an alternative spelling for this flag is--passthrough. this overrides the-C/--context,-A/--after-contextand-B/--before-contextflags.
-p,--prettyโ a convenience alias for--color=always --heading --line-number๐ perfect when you still want pretty output even while piping ripgrep somewhere else. for example:rg -p foo | less -R.-q,--quietโ prints nothing to stdout. if a match is found in a file, ripgrep just stops searching. iconic for when you only care about the exit code (which will be an error code if no matches turn up) ๐
when --files is used, ripgrep stops finding files after it finds the first file that doesn't match any ignore rules.
-r REPLACEMENT,--replace=REPLACEMENTโ swaps every match for the text you give, when printing results. and no โ neither this flag nor any other ripgrep flag will ever modify your files, promise ๐
capture group indices (e.g.,$5) and names (e.g.,$foo) are supported in the replacement string. capture group indices are numbered by the position of the group's opening parenthesis, where the leftmost such group is$1. the special$0group is the entire match. a group's name is formed by taking the longest string of letters, numbers and underscores (i.e.[_0-9A-Za-z]) after the$. for example,$1agets replaced with the group named1a, not the group at index 1. if the group's name has characters that aren't letters, numbers or underscores, or you want to immediately follow the group with another string, wrap the name in braces. for example,${1}atakes the content of the group at index 1 and appendsato the end of it. if an index or name doesn't refer to a valid capture group, it gets replaced with an empty string. in shells like Bash and zsh, wrap the pattern in single quotes instead of double quotes. otherwise, capture group indices get replaced by expanded shell variables, which will most likely be empty ๐ญ to write a literal$, use$$. note that the replacement by default replaces each match, not the entire line. to replace the entire line, you should match the entire line. this flag can be used with the-o/--only-matchingflag.
--sort=SORTBYโ sorts results in ascending order โญ the possible values are:noneโ (Default) do not sort results. fastest. can be multi-threaded.pathโ sort by file path. always single-threaded. the order is determined by sorting files in each directory entry during traversal. this means that given the filesa/banda+, the latter will sort after the former even though+would normally sort before/.modifiedโ sort by the last modified time on a file. always single-threaded.accessedโ sort by the last accessed time on a file. always single-threaded.createdโ sort by the creation time on a file. always single-threaded.
if the chosen (manually or by-default) sorting criteria isn't available on your system (for example, creation time is not available on ext4 file systems), then ripgrep will attempt to detect this, print an error and exit without searching ๐ to sort in reverse or descending order, use the--sortrflag. also, this flag overrides--sortr. note that sorting results currently always forces ripgrep to abandon parallelism and run in a single thread.
--sortr=SORTBYโ sorts results in descending order ๐ the possible values are:noneโ (Default) do not sort results. fastest. can be multi-threaded.pathโ sort by file path. always single-threaded. the order is determined by sorting files in each directory entry during traversal. this means that given the filesa/banda+, the latter will sort before the former even though+would normally sort after/when doing a reverse lexicographic sort.modifiedโ sort by the last modified time on a file. always single-threaded.accessedโ sort by the last accessed time on a file. always single-threaded.createdโ sort by the creation time on a file. always single-threaded.
if the chosen (manually or by-default) sorting criteria isn't available on your system (for example, creation time is not available on ext4 file systems), then ripgrep will attempt to detect this, print an error and exit without searching ๐ to sort in ascending order, use the--sortflag. also, this flag overrides--sort. note that sorting results currently always forces ripgrep to abandon parallelism and run in a single thread.
--trimโ when set, all ASCII whitespace at the beginning of each line printed gets removed ๐
you can turn it off with --no-trim.
--vimgrepโ tells ripgrep to print results with every match on its own line, including line numbers and column numbers ๐ฅ
so yeah, with this flag a line that has more than one match gets printed in full more than once. ๐ญ Which means the total output can be quadratic in the size of the input. Like, if the pattern matches every single byte in a file, then each line gets repeated for every byte matched. Not the vibe. So bestie, please only use this when you have literally no other choice. Editor integrations should lowkey prefer some other way of pulling results out of ripgrep, like via --json. ๐
One way to dodge exorbitant memory usage is to force ripgrep into single threaded mode with-j/--threads. But ngl, that will not change the total size of the output โ it only affects the heap memory ripgrep will use. The output stays huge, it's just the memory that behaves. ๐ซถ
-H,--with-filenameโ tells ripgrep to print the file path for each matching line. This is the default when more than one file is searched. If--headingis on (which is the default when printing to a tty ๐), the file path shows up above clusters of matches from each file; otherwise the file name gets shown as a prefix on each matched line.
This flag overrides -I/--no-filename. โจ
-I,--no-filenameโ tells ripgrep to never print the file path with each matching line. This is the default when ripgrep is explicitly told to search one file or stdin.
This flag overrides -H/--with-filename. ๐
--sort-filesโ DEPRECATED. Use--sort=pathinstead, bestie.
This flag tells ripgrep to sort search results by file path lexicographically in ascending order. Heads up though: this currently disables all parallelism and runs the search in a single thread. ๐
This flag overrides --sort and --sortr.
This flag can be disabled with --no-sort-files.
โจ OUTPUT MODES โจ
okay this is the section where you pick what shape your results come in. pick your fighter. ๐
-c,--countโ suppresses normal output and instead shows the number of lines that match the given patterns, for each file searched. Every file containing a match gets its path and count printed on its own line. ๐
Careful though: unless -U/--multiline is enabled and the pattern(s) can match over multiple lines, this reports the number of lines that match, not the total number of matches. When multiline mode is on and the pattern(s) can match over multiple lines, -c/--count is equivalent to --count-matches. ๐
If only one file is given to ripgrep, then only the count is printed โ if there is a match. The -H/--with-filename flag can force the file path to print in that case. And if you need a count printed regardless of whether there's a match, use --include-zero. ๐
Also, plot twist: it's possible for this flag to give results inconsistent with the output of -l/--files-with-matches. Why? By default, ripgrep tries to avoid searching files with binary data. With this flag, ripgrep has to search the entire content of files, which may include binary data. But with -l/--files-with-matches, ripgrep can stop as soon as it observes a match โ which might come well before any binary data. To avoid this inconsistency without disabling binary detection, use the --binary flag. ๐ง
This overrides the --count-matches flag. And note: when -c/--count is combined with -o/--only-matching, ripgrep behaves as if --count-matches was given.
--count-matchesโ suppresses normal output and shows the number of individual matches of the given patterns for each file searched. Each file containing matches gets its path and match count printed on each line. So this is the total number of individual matches, not the number of lines that match. ๐ฅ
If only one file is given to ripgrep, then only the count is printed โ if there is a match. The -H/--with-filename flag can force the file path to print in this case.
This overrides the -c/--count flag. And note: when -c/--count is combined with -o/--only-matching, ripgrep behaves as if --count-matches was given.
-l,--files-with-matchesโ prints only the paths that have at least one match, and suppresses the match contents. just the receipts, no drama. ๐
Same inconsistency warning as before, bestie: it's possible for this flag to give results inconsistent with -c/--count. By default ripgrep tries to avoid searching files with binary data. With this flag, ripgrep might stop searching before the binary data is observed. But with -c/--count, ripgrep has to search the entire contents to figure out the match count โ which means it might see binary data that causes it to skip searching that file. To avoid this inconsistency without disabling binary detection, use the --binary flag. ๐
This overrides --files-without-match.
--files-without-matchโ prints the paths that contain zero matches, and suppresses match contents. ๐
This overrides -l/--files-with-matches.
--jsonโ enables printing results in a JSON Lines format. ๐ค
When this flag is provided, ripgrep emits a sequence of messages, each encoded as a JSON object, and there are five different message types:
beginโ a message that indicates a file is being searched and contains at least one match.endโ a message that indicates a file is done being searched. This message also includes summary statistics about the search for a particular file.matchโ a message that indicates a match was found. This includes the text and offsets of the match.contextโ a message that indicates a contextual line was found. This includes the text of the line, along with any match information if the search was inverted.summaryโ the final message emitted by ripgrep, containing summary statistics about the search across all files.
Since file paths and the contents of files are not guaranteed to be valid UTF-8, and JSON itself must be representable by a Unicode encoding, ripgrep emits all data elements as objects with one of two keys: text or bytes. text is a normal JSON string when the data is valid UTF-8, while bytes is the base64 encoded contents of the data. ๐
The JSON Lines format is only supported for showing search results. It cannot be used with other flags that emit other types of output, such as --files, -l/--files-with-matches, --files-without-match, -c/--count or --count-matches. ripgrep will report an error if any of the aforementioned flags are used in concert with --json. ๐ค
Other flags that control aspects of standard output โ like -o/--only-matching, --heading, -r/--replace, -M/--max-columns, etc. โ have no effect when --json is set. But enabling JSON output will always implicitly and unconditionally enable --stats. โจ
A more complete description of the JSON format used can be found here: https://docs.rs/grep-printer/*/grep_printer/struct.JSON.html.
This flag can be disabled with --no-json.
๐ฆ LOGGING OPTIONS ๐ฆ
--debugโ show debug messages. Please use this when filing a bug report. ๐
The --debug flag is generally useful for figuring out why ripgrep skipped searching a particular file. The debug messages should mention all files skipped and why they were skipped. ๐ต๏ธ
To get even more debug output, use the --trace flag, which implies --debug along with additional trace data.
--no-ignore-messagesโ when enabled, all error messages related to parsing ignore files are suppressed. By default, error messages are printed to stderr. In cases where these errors are expected, this flag can be used to avoid seeing the noise produced by the messages. ๐
This flag can be disabled with --ignore-messages.
--no-messagesโ suppresses some error messages. Specifically, messages related to the failed opening and reading of files. Error messages related to the syntax of the pattern are still shown. ๐
This flag can be disabled with --messages.
--statsโ when enabled, ripgrep prints aggregate statistics about the search. When this flag is present, ripgrep prints at least the following stats to stdout at the end of the search: number of matched lines, number of files with matches, number of files searched, and the time taken for the entire search to complete. ๐
This set of aggregate statistics may expand over time. โจ
This flag is always and implicitly enabled when --json is used.
Note that this flag has no effect if --files, -l/--files-with-matches or --files-without-match is passed.
This flag can be disabled with --no-stats.
--traceโ show trace messages. This shows even more detail than the--debugflag. Generally, one should only use this if--debugdoesn't emit the information you're looking for. ๐
๐ OTHER BEHAVIORS ๐
--filesโ prints each file that would be searched, without actually performing the search. Super useful for figuring out whether a particular file is being searched or not. ๐
This overrides --type-list.
--generate=KINDโ tells ripgrep to generate some special kind of output identified byKINDand then quit without searching.KINDcan be one of the following values:manโ generates a manual page for ripgrep in the roff format.complete-bashโ generates a completion script for the bash shell.complete-zshโ generates a completion script for the zsh shell.complete-fishโ generates a completion script for the fish shell.complete-powershellโ generates a completion script for PowerShell.
The output is written to stdout. The list above may expand over time. ๐ฑ
--no-configโ when set, ripgrep will never read configuration files. When this flag is present, ripgrep will not respect theRIPGREP_CONFIG_PATHenvironment variable. ๐ซ
If ripgrep ever grows a feature to automatically read configuration files in pre-defined locations, then this flag will also disable that behavior as well.
--pcre2-versionโ when this flag is present, ripgrep prints the version of PCRE2 in use, along with other information, and then exits. If PCRE2 is not available, then ripgrep prints an error message and exits with an error code. ๐ญ--type-listโ shows you every file type ripgrep supports plus the globs that go with each one โจ. It takes any--type-addand--type-clearflags you gave into account, so it's showing you the current truth, not the factory default. Each type gets its own line, then a:and then a comma-delimited list of globs for that type, all on the same line. Chef's kiss.-V,--versionโ prints ripgrep's version ๐. It might also print other relevant stuff, like whether target-specific optimizations are present and the git revision this build of ripgrep was compiled from. Receipts, basically.
๐ช EXIT STATUS
So here's the tea on how ripgrep tells you what happened, bestie:
- Match found โ exit status is
0. - No match could be found โ exit status is
1. - Error happened โ exit status is always
2โฆ unless ripgrep was run with-q/--quietand a match was found. Yes, that's the plot twist.
In summary, in cute little bullet form:
0exit status occurs only when at least one match was found, and if no error occurred, unless-q/--quietwas given.1exit status occurs only when no match was found and no error occurred.2exit status occurs when an error occurred. This is true for both catastrophic errors (e.g., a regex syntax error) and for soft errors (e.g., unable to read a file).
fr fr:2doesn't care how big or small the oopsie was. Regex syntax error? Soft "couldn't read this one file"? Both2. Periodt.
๐งน AUTOMATIC FILTERING
okay so ripgrep does a fair bit of automatic filtering by default, and this section is the whole breakdown of that filtering and how to control it. ๐
TIP: To disable automatic filtering, use rg -uuu.
ripgrep's automatic "smart" filtering is one of the most apparent differentiating features between ripgrep and other tools like grep. As such, its behavior may be surprising to users that aren't expecting it. Consider this your warning label, bestie.
ripgrep does four types of filtering automatically:
- Files and directories that match ignore rules are not searched.
- Hidden files and directories are not searched.
- Binary files (files with a
NULbyte) are not searched. - Symbolic links are not followed.
The first type of filtering is the most sophisticated. ripgrep will attempt to respect your gitignore rules as faithfully as possible. In particular, this includes the following:
- Any global rules, e.g., in
$HOME/.config/git/ignore. - Any rules in relevant
.gitignorefiles. This includes.gitignorefiles in parent directories that are part of the same git repository. (Unless--no-require-gitis given.) - Any local rules, e.g., in
.git/info/exclude.
In some cases, ripgrep and git will not always be in sync in terms of which files are ignored. For example, a file that is ignored via .gitignore but is tracked by git would not be searched by ripgrep even though git tracks it. This is unlikely to ever be fixed ๐. Instead, you should either make sure your exclude rules match the files you track precisely, or otherwise use git grep for search.
Additional ignore rules can be provided outside of a git context:
- Any rules in
.ignore. ripgrep will also respect.ignorefiles in parent directories. - Any rules in
.rgignore. ripgrep will also respect.rgignorefiles in parent directories. - Any rules in files specified with the
--ignore-fileflag.
The precedence of ignore rules is as follows, with later items overriding earlier items:
- Files given by
--ignore-file. - Global gitignore rules, e.g., from
$HOME/.config/git/ignore. - Local rules from
.git/info/exclude. - Rules from
.gitignore. - Rules from
.ignore. - Rules from
.rgignore.
So for example, if foo were in a .gitignore and !foo were in an .rgignore, then foo would not be ignored since .rgignore takes precedence over .gitignore. Iconic behaviour, honestly. ๐
Each of the types of filtering can be configured via command line flags:
- There are several flags starting with
--no-ignorethat toggle which, if any, ignore rules are respected.--no-ignoreby itself will disable all of them. -./--hiddenwill force ripgrep to search hidden files and directories.--binarywill force ripgrep to search binary files.-L/--followwill force ripgrep to follow symlinks.
As a special short hand, the -u flag can be specified up to three times. Each additional time incrementally decreases filtering:
-uis equivalent to--no-ignore.-uuis equivalent to--no-ignore --hidden.-uuuis equivalent to--no-ignore --hidden --binary.
In particular, rg -uuu should search the same exact content as grep -r. ๐ซถ
โ๏ธ CONFIGURATION FILES
ripgrep supports reading configuration files that change ripgrep's default behavior. The format of the configuration file is an "rc" style and is very simple. It is defined by two rules:
- Every line is a shell argument, after trimming whitespace.
- Lines starting with
#(optionally preceded by any amount of whitespace) are ignored.
ripgrep will look for a single configuration file if and only if the RIPGREP_CONFIG_PATH environment variable is set and is non-empty. ripgrep will parse arguments from this file on startup and will behave as if the arguments in this file were prepended to any explicit arguments given to ripgrep on the command line. Note though that the rg command you run must still be valid. That is, it must always contain at least one pattern at the command line, even if the configuration file uses the -e/--regexp flag. No skipping the pattern, babe.
For example, if your ripgreprc file contained a single line:
--smart-case
then the following command
RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo
would behave identically to the following command:
rg --smart-case foo
Another example is adding types, like so:
--type-add
web:*.{html,css,js}*
The above would behave identically to the following command:
rg --type-add 'web:*.{html,css,js}*' foo
The same applies to using globs. This:
--glob=!.git
or this:
--glob
!.git
would behave identically to the following command:
rg --glob '!.git' foo
The bottom line is that every shell argument needs to be on its own line. So for example, a config file containing
-j 4
is probably not doing what you intend. Instead, you want
-j
4
or
-j4
ripgrep also provides a flag, --no-config, that when present will suppress any and all support for configuration. This includes any future support for auto-loading configuration files from pre-determined paths. Future-proofed.
Conflicts between configuration files and explicit arguments are handled exactly like conflicts in the same command line invocation. That is, assuming your config file contains only --smart-case, then this command:
RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo --case-sensitive
is exactly equivalent to
rg --smart-case foo --case-sensitive
in which case, the --case-sensitive flag would override the --smart-case flag. Last one in wins, the way it should be. ๐
๐ SHELL COMPLETION
Shell completion files are included in the release tarball for Bash, Fish, Zsh and PowerShell. So many options, we love an inclusive queen. ๐
For bash, move rg.bash to $XDG_CONFIG_HOME/bash_completion or /etc/bash_completion.d/.
For fish, move rg.fish to $HOME/.config/fish/completions.
For zsh, move _rg to one of your $fpath directories.
โ ๏ธ CAVEATS
ripgrep may abort unexpectedly when using default settings if it searches a file that is simultaneously truncated. This behavior can be avoided by passing the --no-mmap flag which will forcefully disable the use of memory maps in all cases. Not a drill โ actually pass the flag if this is your situation.
ripgrep may use a large amount of memory depending on a few factors. Firstly, if ripgrep uses parallelism for search (the default), then the entire output for each individual file is buffered into memory in order to prevent interleaving matches in the output. To avoid this, you can disable parallelism with the -j1 flag. Secondly, ripgrep always needs to have at least a single line in memory in order to execute a search. A file with a very long line can thus cause ripgrep to use a lot of memory. Generally, this only occurs when searching binary data with the -a/--text flag enabled. (When the -a/--text flag isn't enabled, ripgrep will replace all NUL bytes with line terminators, which typically prevents exorbitant memory usage.) Thirdly, when ripgrep searches a large file using a memory map, the process will likely report its resident memory usage as the size of the file. However, this does not mean ripgrep actually needed to use that much heap memory; the operating system will generally handle this for you. So like, breathe. ๐ฎโ๐จ
๐ VERSION
15.2.0
๐ HOMEPAGE
https://github.com/BurntSushi/ripgrep
Please report bugs and feature requests to the issue tracker. Please do your best to provide a reproducible test case for bugs. This should include the corpus being searched, the rg command, the actual output and the expected output. Please also include the output of running the same rg command but with the --debug flag.
If you have questions that don't obviously fall into the "bug" or "feature request" category, then they are welcome in the Discussions section of the issue tracker: https://github.com/BurntSushi/ripgrep/discussions. ๐ฆ
โ๏ธ AUTHORS
Andrew Gallant <jamslam@gmail.com>
okay bestie that's the whole page, we made it ๐ huge slay, no notes. This was ripgrep 15.2.0, dated 2026-07-15, and it's RG(1) โ go forth and search responsibly, mwah ๐
๐
๐ฆ where this page comes from
- arch rolling: ripgrep 15.2.0-1 ยท MIT OR Unlicense
- epel 10: ripgrep 15.2.0-1.el10_3 ยท (Unlicense OR MIT) AND BSD-3-Clause AND MIT AND Unicode-DFS-2016 AND (MIT OR Apache-2.0)
- epel 9: ripgrep 15.2.0-1.el9 ยท (Unlicense OR MIT) AND BSD-3-Clause AND MIT AND Unicode-DFS-2016 AND (MIT OR Apache-2.0)
- fedora 43: ripgrep 15.2.0-1.fc43 ยท (Unlicense OR MIT) AND BSD-3-Clause AND MIT AND Unicode-DFS-2016 AND (MIT OR Apache-2.0)
- fedora 44: ripgrep 15.2.0-1.fc44 ยท (Unlicense OR MIT) AND BSD-3-Clause AND MIT AND Unicode-DFS-2016 AND (MIT OR Apache-2.0)
- nixpkgs unstable: ripgrep 15.2.0
- ubuntu stonking: ripgrep 15.2.0-1 ยท Unlicense OR MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms