2018-02-06 01:45:45 +02:00
|
|
|
rg(1)
|
|
|
|
=====
|
|
|
|
|
|
|
|
Name
|
|
|
|
----
|
|
|
|
rg - recursively search current directory for lines matching a pattern
|
|
|
|
|
|
|
|
|
|
|
|
Synopsis
|
|
|
|
--------
|
|
|
|
*rg* [_OPTIONS_] _PATTERN_ [_PATH_...]
|
|
|
|
|
2018-02-07 01:49:30 +02:00
|
|
|
*rg* [_OPTIONS_] *-e* _PATTERN_... [_PATH_...]
|
|
|
|
|
2018-02-23 19:17:53 +02:00
|
|
|
*rg* [_OPTIONS_] *-f* _PATTERNFILE_... [_PATH_...]
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
*rg* [_OPTIONS_] *--files* [_PATH_...]
|
|
|
|
|
|
|
|
*rg* [_OPTIONS_] *--type-list*
|
|
|
|
|
2018-07-22 15:38:49 +02:00
|
|
|
*command* | *rg* [_OPTIONS_] _PATTERN_
|
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
*rg* [_OPTIONS_] *--help*
|
|
|
|
|
|
|
|
*rg* [_OPTIONS_] *--version*
|
|
|
|
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
|
|
|
ripgrep (rg) recursively searches your current directory for a regex pattern.
|
2018-08-22 03:24:02 +02:00
|
|
|
By default, ripgrep will respect your .gitignore and automatically skip hidden
|
|
|
|
files/directories and binary files.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
2018-08-22 03:24:02 +02:00
|
|
|
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
|
2019-01-26 21:12:47 +02:00
|
|
|
the *--pcre2* flag can be used to enable backreferences and look-around.
|
2018-08-22 03:24:02 +02:00
|
|
|
|
2019-01-26 21:12:47 +02:00
|
|
|
ripgrep supports configuration files. Set *RIPGREP_CONFIG_PATH* to a
|
2018-08-22 03:24:02 +02:00
|
|
|
configuration file. The file can specify one shell argument per line. Lines
|
2019-01-26 21:12:47 +02:00
|
|
|
starting with *#* are ignored. For more details, see the man page or the
|
|
|
|
*README*.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
binary: rejigger ripgrep's handling of binary files
This commit attempts to surface binary filtering in a slightly more
user friendly way. Namely, before, ripgrep would silently stop
searching a file if it detected a NUL byte, even if it had previously
printed a match. This can lead to the user quite reasonably assuming
that there are no more matches, since a partial search is fairly
unintuitive. (ripgrep has this behavior by default because it really
wants to NOT search binary files at all, just like it doesn't search
gitignored or hidden files.)
With this commit, if a match has already been printed and ripgrep detects
a NUL byte, then it will print a warning message indicating that the search
stopped prematurely.
Moreover, this commit adds a new flag, --binary, which causes ripgrep to
stop filtering binary files, but in a way that still avoids dumping
binary data into terminals. That is, the --binary flag makes ripgrep
behave more like grep's default behavior.
For files explicitly specified in a search, e.g., `rg foo some-file`,
then no binary filtering is applied (just like no gitignore and no
hidden file filtering is applied). Instead, ripgrep behaves as if you
gave the --binary flag for all explicitly given files.
This was a fairly invasive change, and potentially increases the UX
complexity of ripgrep around binary files. (Before, there were two
binary modes, where as now there are three.) However, ripgrep is now a
bit louder with warning messages when binary file detection might
otherwise be hiding potential matches, so hopefully this is a net
improvement.
Finally, the `-uuu` convenience now maps to `--no-ignore --hidden
--binary`, since this is closer to the actualy intent of the
`--unrestricted` flag, i.e., to reduce ripgrep's smart filtering. As a
consequence, `rg -uuu foo` should now search roughly the same number of
bytes as `grep -r foo`, and `rg -uuua foo` should search roughly the
same number of bytes as `grep -ra foo`. (The "roughly" weasel word is
used because grep's and ripgrep's binary file detection might differ
somewhat---perhaps based on buffer sizes---which can impact exactly what
is and isn't searched.)
See the numerous tests in tests/binary.rs for intended behavior.
Fixes #306, Fixes #855
2019-04-09 01:28:38 +02:00
|
|
|
Tip: to disable all smart filtering and make ripgrep behave a bit more like
|
|
|
|
classical grep, use *rg -uuu*.
|
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
|
2018-02-07 01:49:30 +02:00
|
|
|
REGEX SYNTAX
|
|
|
|
------------
|
2018-08-22 03:24:02 +02:00
|
|
|
ripgrep uses Rust's regex engine by default, which documents its syntax:
|
|
|
|
https://docs.rs/regex/*/regex/#syntax
|
2018-02-07 01:49:30 +02:00
|
|
|
|
|
|
|
ripgrep uses byte-oriented regexes, which has some additional documentation:
|
2018-08-22 03:24:02 +02:00
|
|
|
https://docs.rs/regex/*/regex/bytes/index.html#syntax
|
2018-02-07 01:49:30 +02:00
|
|
|
|
|
|
|
To a first approximation, ripgrep uses Perl-like regexes without look-around or
|
|
|
|
backreferences. This makes them very similar to the "extended" (ERE) regular
|
2019-01-26 21:12:47 +02:00
|
|
|
expressions supported by *egrep*, but with a few additional features like
|
2018-02-07 01:49:30 +02:00
|
|
|
Unicode character classes.
|
|
|
|
|
2019-01-26 21:12:47 +02:00
|
|
|
If you're using ripgrep with the *--pcre2* flag, then please consult
|
2018-08-22 03:24:02 +02:00
|
|
|
https://www.pcre.org or the PCRE2 man pages for documentation on the supported
|
|
|
|
syntax.
|
|
|
|
|
2018-02-07 01:49:30 +02:00
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
POSITIONAL ARGUMENTS
|
|
|
|
--------------------
|
|
|
|
_PATTERN_::
|
|
|
|
A regular expression used for searching. To match a pattern beginning with a
|
|
|
|
dash, use the -e/--regexp option.
|
|
|
|
|
|
|
|
_PATH_::
|
|
|
|
A file or directory to search. Directories are searched recursively. Paths
|
2019-01-14 13:50:30 +02:00
|
|
|
specified explicitly on the command line override glob and ignore rules.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-------
|
2019-01-26 21:12:47 +02:00
|
|
|
Note that for many options, there exist flags to disable them. In some cases,
|
|
|
|
those flags are not listed in a first class way 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 on the command
|
|
|
|
line. Each flag's documentation notes whether an inverted flag exists. In all
|
|
|
|
cases, the flag specified last takes precedence.
|
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
{OPTIONS}
|
|
|
|
|
|
|
|
|
|
|
|
EXIT STATUS
|
|
|
|
-----------
|
|
|
|
If ripgrep finds a match, then the exit status of the program is 0. If no match
|
2019-01-26 21:36:34 +02:00
|
|
|
could be found, then the exit status is 1. If an error occurred, then the exit
|
2019-01-26 22:42:55 +02:00
|
|
|
status is always 2 unless ripgrep was run with the *--quiet* flag and a match
|
|
|
|
was found. In summary:
|
|
|
|
|
|
|
|
* `0` exit status occurs only when at least one match was found, and if
|
|
|
|
no error occurred, unless *--quiet* was given.
|
|
|
|
* `1` exit status occurs only when no match was found and no error occurred.
|
|
|
|
* `2` exit 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).
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
2019-04-04 21:14:29 +02:00
|
|
|
1. Every line is a shell argument, after trimming whitespace.
|
2019-01-26 21:12:47 +02:00
|
|
|
2. Lines starting with *#* (optionally preceded by any amount of
|
2019-04-04 21:14:29 +02:00
|
|
|
whitespace) are ignored.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
ripgrep will look for a single configuration file if and only if the
|
2019-01-26 21:12:47 +02:00
|
|
|
*RIPGREP_CONFIG_PATH* environment variable is set and is non-empty.
|
2018-02-06 01:45:45 +02:00
|
|
|
ripgrep will parse shell 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.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-05-25 12:42:05 +02:00
|
|
|
another example is adding types
|
|
|
|
|
|
|
|
--type-add
|
|
|
|
web:*.{html,css,js}*
|
|
|
|
|
|
|
|
would behave identically to the following command
|
|
|
|
|
|
|
|
rg --type-add 'web:*.{html,css,js}*' foo
|
|
|
|
|
|
|
|
same with using globs
|
|
|
|
|
2019-08-07 19:47:18 +02:00
|
|
|
--glob=!.git
|
2018-05-25 12:42:05 +02:00
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
--glob
|
2019-08-07 19:47:18 +02:00
|
|
|
!.git
|
2018-05-25 12:42:05 +02:00
|
|
|
|
|
|
|
would behave identically to the following command
|
|
|
|
|
2019-08-07 19:47:18 +02:00
|
|
|
rg --glob '!.git' foo
|
2018-05-25 12:42:05 +02:00
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
Conflicts between configuration files and explicit arguments are handled
|
|
|
|
exactly like conflicts in the same command line invocation. That is,
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
SHELL COMPLETION
|
|
|
|
----------------
|
|
|
|
Shell completion files are included in the release tarball for Bash, Fish, Zsh
|
|
|
|
and PowerShell.
|
|
|
|
|
2019-01-26 21:12:47 +02:00
|
|
|
For *bash*, move *rg.bash* to *$XDG_CONFIG_HOME/bash_completion*
|
|
|
|
or */etc/bash_completion.d/*.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
2019-01-26 21:12:47 +02:00
|
|
|
For *fish*, move *rg.fish* to *$HOME/.config/fish/completions*.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
2019-01-26 21:12:47 +02:00
|
|
|
For *zsh*, move *_rg* to one of your *$fpath* directories.
|
2018-02-07 01:49:30 +02:00
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
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
|
2019-01-26 21:12:47 +02:00
|
|
|
the *--no-mmap* flag which will forcefully disable the use of memory maps in
|
|
|
|
all cases.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
2019-04-14 16:53:39 +02:00
|
|
|
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* flag enabled. (When the *-a* 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 report its resident memory
|
|
|
|
usage as the size of the file. However, this does not mean ripgrep actually
|
|
|
|
needed to use that much memory; the operating system will generally handle this
|
|
|
|
for you.
|
|
|
|
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
VERSION
|
|
|
|
-------
|
|
|
|
{VERSION}
|
|
|
|
|
|
|
|
|
|
|
|
HOMEPAGE
|
|
|
|
--------
|
|
|
|
https://github.com/BurntSushi/ripgrep
|
|
|
|
|
2019-01-26 21:12:47 +02:00
|
|
|
Please report bugs and feature requests in 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.
|
2018-02-06 01:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
-------
|
|
|
|
Andrew Gallant <jamslam@gmail.com>
|