13 KiB
13 KiB
obj | repo | aliases | |
---|---|---|---|
application | https://github.com/BurntSushi/ripgrep |
|
ripgrep
ripgrep is a line-oriented search tool that recursively searches the current directory for a regex pattern. By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files. ripgrep has first class support on Windows, macOS and Linux with binary downloads available for every release. ripgrep is similar to other popular search tools like The Silver Searcher, ack and grep.
Usage
rg [OPTIONS] PATTERN [PATH ...]
rg [OPTIONS] -e PATTERN ... [PATH ...]
rg [OPTIONS] -f PATTERNFILE ... [PATH ...]
Options
Option | Description |
---|---|
-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. |
-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/--regexp flag, 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. |
--pre=COMMAND |
For each input PATH , this flag causes ripgrep to search the standard output of <COMMAND> <PATH> instead of the contents of PATH . This option expects the COMMAND program to either be a path or to be available in your $PATH . |
-z, --search-zip |
This flag instructs ripgrep to search in compressed files. |
-s, --case-sensitive |
Execute the search case sensitively. This is the default mode. |
-i, --ignore-case |
When this flag is provided, all patterns will be searched case insensitively. |
-v, --invert-match |
This flag inverts matching. That is, instead of printing lines that match, ripgrep will print lines that don't match. |
-x, --line-regexp |
When enabled, ripgrep will only show matches surrounded by line boundaries. This is equivalent to surrounding every pattern with ^ and $ . In other words, this only prints lines where the entire line participates in a match. |
-m NUM, --max-count=NUM |
Limit the number of matching lines per file searched to NUM. |
-U, --multiline |
This flag enable searching across multiple lines. |
-S, --smart-case |
This flag instructs ripgrep to searches case insensitively if the pattern is all lowercase. Otherwise, ripgrep will search case sensitively. |
--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. |
-j NUM, --threads=NUM |
This flag sets the approximate number of threads to use. A value of 0 (which is the default) causes ripgrep to choose the thread count using heuristics. |
-L, --follow |
This flag instructs ripgrep to follow symbolic links while traversing directories. This behavior is disabled by default. This flag can be disabled with --no-follow . |
-., --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 argumnet to ripgrep. This flag can be disabled with --no-hidden . |
-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 .gitignore globs. 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. |
--ignore-file=PATH |
Specifies a path to one or more gitignore formatted rules files. These patterns are applied after the patterns found in .gitignore , .rgignore and .ignore are applied and are matched relative to the current working directory. Multiple additional ignore files can be specified by using this flag repeatedly. When specifying multiple ignore files, earlier files have lower precedence than later files. |
-d NUM, --max-depth=NUM |
This flag limits the depth of directory traversal to NUM levels beyond the paths given. A value of 0 only searches the explicitly given paths themselves. |
-A NUM, --after-context=NUM |
Show NUM lines after each match. |
-B NUM, --before-context=NUM |
Show NUM lines before each match. |
-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. |
-c, --count |
This flag suppresses normal output and shows the number of lines that match the given patterns for each file searched. Each file containing a match has its path and count printed on each line. |
--count-matches |
This flag suppresses normal output and shows the number of individual matches of the given patterns for each file searched. Each file containing matches has its path and match count printed on each line. Note that this reports the total number of individual matches and not the number of lines that match. |
-l, --files-with-matches |
Print only the paths with at least one match and suppress match contents. |
--files-without-match |
Print the paths that contain zero matches and suppress match contents. |
--json |
Enable printing results in a JSON Lines format. When this flag is provided, ripgrep will emit a sequence of messages, each encoded as a JSON object. |