Advertisement
Guest User

rg --help

a guest
Jan 3rd, 2020
2,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.88 KB | None | 0 0
  1. ripgrep 11.0.2
  2. Andrew Gallant <jamslam@gmail.com>
  3.  
  4. ripgrep (rg) recursively searches your current directory for a regex pattern.
  5. By default, ripgrep will respect your .gitignore and automatically skip hidden
  6. files/directories and binary files.
  7.  
  8. ripgrep's default regex engine uses finite automata and guarantees linear
  9. time searching. Because of this, features like backreferences and arbitrary
  10. look-around are not supported. However, if ripgrep is built with PCRE2, then
  11. the --pcre2 flag can be used to enable backreferences and look-around.
  12.  
  13. ripgrep supports configuration files. Set RIPGREP_CONFIG_PATH to a
  14. configuration file. The file can specify one shell argument per line. Lines
  15. starting with '#' are ignored. For more details, see the man page or the
  16. README.
  17.  
  18. Tip: to disable all smart filtering and make ripgrep behave a bit more like
  19. classical grep, use 'rg -uuu'.
  20.  
  21. Project home page: https://github.com/BurntSushi/ripgrep
  22.  
  23. Use -h for short descriptions and --help for more details.
  24.  
  25. USAGE:
  26. rg [OPTIONS] PATTERN [PATH ...]
  27. rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]
  28. rg [OPTIONS] --files [PATH ...]
  29. rg [OPTIONS] --type-list
  30. command | rg [OPTIONS] PATTERN
  31.  
  32. ARGS:
  33. <PATTERN>
  34. A regular expression used for searching. To match a pattern beginning with a
  35. dash, use the -e/--regexp flag.
  36.  
  37. For example, to search for the literal '-foo', you can use this flag:
  38.  
  39. rg -e -foo
  40.  
  41. You can also use the special '--' delimiter to indicate that no more flags
  42. will be provided. Namely, the following is equivalent to the above:
  43.  
  44. rg -- -foo
  45.  
  46. <PATH>...
  47. A file or directory to search. Directories are searched recursively. Paths specified on
  48. the command line override glob and ignore rules.
  49.  
  50. OPTIONS:
  51. -A, --after-context <NUM>
  52. Show NUM lines after each match.
  53.  
  54. This overrides the --context flag.
  55.  
  56. --auto-hybrid-regex
  57. When this flag is used, ripgrep will dynamically choose between supported regex
  58. engines depending on the features used in a pattern. When ripgrep chooses a
  59. regex engine, it applies that choice for every regex provided to ripgrep (e.g.,
  60. via multiple -e/--regexp or -f/--file flags).
  61.  
  62. As an example of how this flag might behave, ripgrep will attempt to use
  63. its default finite automata based regex engine whenever the pattern can be
  64. successfully compiled with that regex engine. If PCRE2 is enabled and if the
  65. pattern given could not be compiled with the default regex engine, then PCRE2
  66. will be automatically used for searching. If PCRE2 isn't available, then this
  67. flag has no effect because there is only one regex engine to choose from.
  68.  
  69. In the future, ripgrep may adjust its heuristics for how it decides which
  70. regex engine to use. In general, the heuristics will be limited to a static
  71. analysis of the patterns, and not to any specific runtime behavior observed
  72. while searching files.
  73.  
  74. The primary downside of using this flag is that it may not always be obvious
  75. which regex engine ripgrep uses, and thus, the match semantics or performance
  76. profile of ripgrep may subtly and unexpectedly change. However, in many cases,
  77. all regex engines will agree on what constitutes a match and it can be nice
  78. to transparently support more advanced regex features like look-around and
  79. backreferences without explicitly needing to enable them.
  80.  
  81. This flag can be disabled with --no-auto-hybrid-regex.
  82.  
  83. -B, --before-context <NUM>
  84. Show NUM lines before each match.
  85.  
  86. This overrides the --context flag.
  87.  
  88. --binary
  89. Enabling this flag will cause ripgrep to search binary files. By default,
  90. ripgrep attempts to automatically skip binary files in order to improve the
  91. relevance of results and make the search faster.
  92.  
  93. Binary files are heuristically detected based on whether they contain a NUL
  94. byte or not. By default (without this flag set), once a NUL byte is seen,
  95. ripgrep will stop searching the file. Usually, NUL bytes occur in the beginning
  96. of most binary files. If a NUL byte occurs after a match, then ripgrep will
  97. still stop searching the rest of the file, but a warning will be printed.
  98.  
  99. In contrast, when this flag is provided, ripgrep will continue searching a file
  100. even if a NUL byte is found. In particular, if a NUL byte is found then ripgrep
  101. will continue searching until either a match is found or the end of the file is
  102. reached, whichever comes sooner. If a match is found, then ripgrep will stop
  103. and print a warning saying that the search stopped prematurely.
  104.  
  105. If you want ripgrep to search a file without any special NUL byte handling at
  106. all (and potentially print binary data to stdout), then you should use the
  107. '-a/--text' flag.
  108.  
  109. The '--binary' flag is a flag for controlling ripgrep's automatic filtering
  110. mechanism. As such, it does not need to be used when searching a file
  111. explicitly or when searching stdin. That is, it is only applicable when
  112. recursively searching a directory.
  113.  
  114. Note that when the '-u/--unrestricted' flag is provided for a third time, then
  115. this flag is automatically enabled.
  116.  
  117. This flag can be disabled with '--no-binary'. It overrides the '-a/--text'
  118. flag.
  119.  
  120. --block-buffered
  121. When enabled, ripgrep will use block buffering. That is, whenever a matching
  122. line is found, it will be written to an in-memory buffer and will not be
  123. written to stdout until the buffer reaches a certain size. This is the default
  124. when ripgrep's stdout is redirected to a pipeline or a file. When ripgrep's
  125. stdout is connected to a terminal, line buffering will be used. Forcing block
  126. buffering can be useful when dumping a large amount of contents to a terminal.
  127.  
  128. Forceful block buffering can be disabled with --no-block-buffered. Note that
  129. using --no-block-buffered causes ripgrep to revert to its default behavior of
  130. automatically detecting the buffering strategy. To force line buffering, use
  131. the --line-buffered flag.
  132.  
  133. -b, --byte-offset
  134. Print the 0-based byte offset within the input file before each line of output.
  135. If -o (--only-matching) is specified, print the offset of the matching part
  136. itself.
  137.  
  138. If ripgrep does transcoding, then the byte offset is in terms of the the result
  139. of transcoding and not the original data. This applies similarly to another
  140. transformation on the source, such as decompression or a --pre filter. Note
  141. that when the PCRE2 regex engine is used, then UTF-8 transcoding is done by
  142. default.
  143.  
  144. -s, --case-sensitive
  145. Search case sensitively.
  146.  
  147. This overrides the -i/--ignore-case and -S/--smart-case flags.
  148.  
  149. --color <WHEN>
  150. This flag controls when to use colors. The default setting is 'auto', which
  151. means ripgrep will try to guess when to use colors. For example, if ripgrep is
  152. printing to a terminal, then it will use colors, but if it is redirected to a
  153. file or a pipe, then it will suppress color output. ripgrep will suppress color
  154. output in some other circumstances as well. For example, if the TERM
  155. environment variable is not set or set to 'dumb', then ripgrep will not use
  156. colors.
  157.  
  158. The possible values for this flag are:
  159.  
  160. never Colors will never be used.
  161. auto The default. ripgrep tries to be smart.
  162. always Colors will always be used regardless of where output is sent.
  163. ansi Like 'always', but emits ANSI escapes (even in a Windows console).
  164.  
  165. When the --vimgrep flag is given to ripgrep, then the default value for the
  166. --color flag changes to 'never'.
  167.  
  168. --colors <COLOR_SPEC>...
  169. This flag specifies color settings for use in the output. This flag may be
  170. provided multiple times. Settings are applied iteratively. Colors are limited
  171. to one of eight choices: red, blue, green, cyan, magenta, yellow, white and
  172. black. Styles are limited to nobold, bold, nointense, intense, nounderline
  173. or underline.
  174.  
  175. The format of the flag is '{type}:{attribute}:{value}'. '{type}' should be
  176. one of path, line, column or match. '{attribute}' can be fg, bg or style.
  177. '{value}' is either a color (for fg and bg) or a text style. A special format,
  178. '{type}:none', will clear all color settings for '{type}'.
  179.  
  180. For example, the following command will change the match color to magenta and
  181. the background color for line numbers to yellow:
  182.  
  183. rg --colors 'match:fg:magenta' --colors 'line:bg:yellow' foo.
  184.  
  185. Extended colors can be used for '{value}' when the terminal supports ANSI color
  186. sequences. These are specified as either 'x' (256-color) or 'x,x,x' (24-bit
  187. truecolor) where x is a number between 0 and 255 inclusive. x may be given as
  188. a normal decimal number or a hexadecimal number, which is prefixed by `0x`.
  189.  
  190. For example, the following command will change the match background color to
  191. that represented by the rgb value (0,128,255):
  192.  
  193. rg --colors 'match:bg:0,128,255'
  194.  
  195. or, equivalently,
  196.  
  197. rg --colors 'match:bg:0x0,0x80,0xFF'
  198.  
  199. Note that the the intense and nointense style flags will have no effect when
  200. used alongside these extended color codes.
  201.  
  202. --column
  203. Show column numbers (1-based). This only shows the column numbers for the first
  204. match on each line. This does not try to account for Unicode. One byte is equal
  205. to one column. This implies --line-number.
  206.  
  207. This flag can be disabled with --no-column.
  208.  
  209. -C, --context <NUM>
  210. Show NUM lines before and after each match. This is equivalent to providing
  211. both the -B/--before-context and -A/--after-context flags with the same value.
  212.  
  213. This overrides both the -B/--before-context and -A/--after-context flags.
  214.  
  215. --context-separator <SEPARATOR>
  216. The string used to separate non-contiguous context lines in the output. Escape
  217. sequences like \x7F or \t may be used. The default value is --.
  218.  
  219. -c, --count
  220. This flag suppresses normal output and shows the number of lines that match
  221. the given patterns for each file searched. Each file containing a match has its
  222. path and count printed on each line. Note that this reports the number of lines
  223. that match and not the total number of matches.
  224.  
  225. If only one file is given to ripgrep, then only the count is printed if there
  226. is a match. The --with-filename flag can be used to force printing the file
  227. path in this case.
  228.  
  229. This overrides the --count-matches flag. Note that when --count is combined
  230. with --only-matching, then ripgrep behaves as if --count-matches was given.
  231.  
  232. --count-matches
  233. This flag suppresses normal output and shows the number of individual
  234. matches of the given patterns for each file searched. Each file
  235. containing matches has its path and match count printed on each line.
  236. Note that this reports the total number of individual matches and not
  237. the number of lines that match.
  238.  
  239. If only one file is given to ripgrep, then only the count is printed if there
  240. is a match. The --with-filename flag can be used to force printing the file
  241. path in this case.
  242.  
  243. This overrides the --count flag. Note that when --count is combined with
  244. --only-matching, then ripgrep behaves as if --count-matches was given.
  245.  
  246. --crlf
  247. When enabled, ripgrep will treat CRLF ('\r\n') as a line terminator instead
  248. of just '\n'.
  249.  
  250. Principally, this permits '$' in regex patterns to match just before CRLF
  251. instead of just before LF. The underlying regex engine may not support this
  252. natively, so ripgrep will translate all instances of '$' to '(?:\r??$)'. This
  253. may produce slightly different than desired match offsets. It is intended as a
  254. work-around until the regex engine supports this natively.
  255.  
  256. CRLF support can be disabled with --no-crlf.
  257.  
  258. --debug
  259. Show debug messages. Please use this when filing a bug report.
  260.  
  261. The --debug flag is generally useful for figuring out why ripgrep skipped
  262. searching a particular file. The debug messages should mention all files
  263. skipped and why they were skipped.
  264.  
  265. To get even more debug output, use the --trace flag, which implies --debug
  266. along with additional trace data. With --trace, the output could be quite
  267. large and is generally more useful for development.
  268.  
  269. --dfa-size-limit <NUM+SUFFIX?>
  270. The upper size limit of the regex DFA. The default limit is 10M. This should
  271. only be changed on very large regex inputs where the (slower) fallback regex
  272. engine may otherwise be used if the limit is reached.
  273.  
  274. The argument accepts the same size suffixes as allowed in with the
  275. --max-filesize flag.
  276.  
  277. -E, --encoding <ENCODING>
  278. Specify the text encoding that ripgrep will use on all files searched. The
  279. default value is 'auto', which will cause ripgrep to do a best effort automatic
  280. detection of encoding on a per-file basis. Automatic detection in this case
  281. only applies to files that begin with a UTF-8 or UTF-16 byte-order mark (BOM).
  282. No other automatic detection is performed. One can also specify 'none' which
  283. will then completely disable BOM sniffing and always result in searching the
  284. raw bytes, including a BOM if it's present, regardless of its encoding.
  285.  
  286. Other supported values can be found in the list of labels here:
  287. https://encoding.spec.whatwg.org/#concept-encoding-get
  288.  
  289. For more details on encoding and how ripgrep deals with it, see GUIDE.md.
  290.  
  291. This flag can be disabled with --no-encoding.
  292.  
  293. -f, --file <PATTERNFILE>...
  294. Search for patterns from the given file, with one pattern per line. When this
  295. flag is used multiple times or in combination with the -e/--regexp flag,
  296. then all patterns provided are searched. Empty pattern lines will match all
  297. input lines, and the newline is not counted as part of the pattern.
  298.  
  299. A line is printed if and only if it matches at least one of the patterns.
  300.  
  301. --files
  302. Print each file that would be searched without actually performing the search.
  303. This is useful to determine whether a particular file is being searched or not.
  304.  
  305. -l, --files-with-matches
  306. Only print the paths with at least one match.
  307.  
  308. This overrides --files-without-match.
  309.  
  310. --files-without-match
  311. Only print the paths that contain zero matches. This inverts/negates the
  312. --files-with-matches flag.
  313.  
  314. This overrides --files-with-matches.
  315.  
  316. -F, --fixed-strings
  317. Treat the pattern as a literal string instead of a regular expression. When
  318. this flag is used, special regular expression meta characters such as .(){}*+
  319. do not need to be escaped.
  320.  
  321. This flag can be disabled with --no-fixed-strings.
  322.  
  323. -L, --follow
  324. When this flag is enabled, ripgrep will follow symbolic links while traversing
  325. directories. This is disabled by default. Note that ripgrep will check for
  326. symbolic link loops and report errors if it finds one.
  327.  
  328. This flag can be disabled with --no-follow.
  329.  
  330. -g, --glob <GLOB>...
  331. Include or exclude files and directories for searching that match the given
  332. glob. This always overrides any other ignore logic. Multiple glob flags may be
  333. used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
  334. it.
  335.  
  336. --glob-case-insensitive
  337. Process glob patterns given with the -g/--glob flag case insensitively. This
  338. effectively treats --glob as --iglob.
  339.  
  340. This flag can be disabled with the --no-glob-case-insensitive flag.
  341.  
  342. -h, --help
  343. Prints help information. Use --help for more details.
  344.  
  345. --heading
  346. This flag prints the file path above clusters of matches from each file instead
  347. of printing the file path as a prefix for each matched line. This is the
  348. default mode when printing to a terminal.
  349.  
  350. This overrides the --no-heading flag.
  351.  
  352. --hidden
  353. Search hidden files and directories. By default, hidden files and directories
  354. are skipped. Note that if a hidden file or a directory is whitelisted in an
  355. ignore file, then it will be searched even if this flag isn't provided.
  356.  
  357. This flag can be disabled with --no-hidden.
  358.  
  359. --iglob <GLOB>...
  360. Include or exclude files and directories for searching that match the given
  361. glob. This always overrides any other ignore logic. Multiple glob flags may be
  362. used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
  363. it. Globs are matched case insensitively.
  364.  
  365. -i, --ignore-case
  366. When this flag is provided, the given patterns will be searched case
  367. insensitively. The case insensitivity rules used by ripgrep conform to
  368. Unicode's "simple" case folding rules.
  369.  
  370. This flag overrides -s/--case-sensitive and -S/--smart-case.
  371.  
  372. --ignore-file <PATH>...
  373. Specifies a path to one or more .gitignore format rules files. These patterns
  374. are applied after the patterns found in .gitignore and .ignore are applied
  375. and are matched relative to the current working directory. Multiple additional
  376. ignore files can be specified by using the --ignore-file flag several times.
  377. When specifying multiple ignore files, earlier files have lower precedence
  378. than later files.
  379.  
  380. If you are looking for a way to include or exclude files and directories
  381. directly on the command line, then used -g instead.
  382.  
  383. --ignore-file-case-insensitive
  384. Process ignore files (.gitignore, .ignore, etc.) case insensitively. Note that
  385. this comes with a performance penalty and is most useful on case insensitive
  386. file systems (such as Windows).
  387.  
  388. This flag can be disabled with the --no-ignore-file-case-insensitive flag.
  389.  
  390. -v, --invert-match
  391. Invert matching. Show lines that do not match the given patterns.
  392.  
  393. --json
  394. Enable printing results in a JSON Lines format.
  395.  
  396. When this flag is provided, ripgrep will emit a sequence of messages, each
  397. encoded as a JSON object, where there are five different message types:
  398.  
  399. **begin** - A message that indicates a file is being searched and contains at
  400. least one match.
  401.  
  402. **end** - A message the indicates a file is done being searched. This message
  403. also include summary statistics about the search for a particular file.
  404.  
  405. **match** - A message that indicates a match was found. This includes the text
  406. and offsets of the match.
  407.  
  408. **context** - A message that indicates a contextual line was found. This
  409. includes the text of the line, along with any match information if the search
  410. was inverted.
  411.  
  412. **summary** - The final message emitted by ripgrep that contains summary
  413. statistics about the search across all files.
  414.  
  415. Since file paths or the contents of files are not guaranteed to be valid UTF-8
  416. and JSON itself must be representable by a Unicode encoding, ripgrep will emit
  417. all data elements as objects with one of two keys: 'text' or 'bytes'. 'text' is
  418. a normal JSON string when the data is valid UTF-8 while 'bytes' is the base64
  419. encoded contents of the data.
  420.  
  421. The JSON Lines format is only supported for showing search results. It cannot
  422. be used with other flags that emit other types of output, such as --files,
  423. --files-with-matches, --files-without-match, --count or --count-matches.
  424. ripgrep will report an error if any of the aforementioned flags are used in
  425. concert with --json.
  426.  
  427. Other flags that control aspects of the standard output such as
  428. --only-matching, --heading, --replace, --max-columns, etc., have no effect
  429. when --json is set.
  430.  
  431. A more complete description of the JSON format used can be found here:
  432. https://docs.rs/grep-printer/*/grep_printer/struct.JSON.html
  433.  
  434. The JSON Lines format can be disabled with --no-json.
  435.  
  436. --line-buffered
  437. When enabled, ripgrep will use line buffering. That is, whenever a matching
  438. line is found, it will be flushed to stdout immediately. This is the default
  439. when ripgrep's stdout is connected to a terminal, but otherwise, ripgrep will
  440. use block buffering, which is typically faster. This flag forces ripgrep to
  441. use line buffering even if it would otherwise use block buffering. This is
  442. typically useful in shell pipelines, e.g.,
  443. 'tail -f something.log | rg foo --line-buffered | rg bar'.
  444.  
  445. Forceful line buffering can be disabled with --no-line-buffered. Note that
  446. using --no-line-buffered causes ripgrep to revert to its default behavior of
  447. automatically detecting the buffering strategy. To force block buffering, use
  448. the --block-buffered flag.
  449.  
  450. -n, --line-number
  451. Show line numbers (1-based). This is enabled by default when searching in a
  452. terminal.
  453.  
  454. -x, --line-regexp
  455. Only show matches surrounded by line boundaries. This is equivalent to putting
  456. ^...$ around all of the search patterns. In other words, this only prints lines
  457. where the entire line participates in a match.
  458.  
  459. This overrides the --word-regexp flag.
  460.  
  461. -M, --max-columns <NUM>
  462. Don't print lines longer than this limit in bytes. Longer lines are omitted,
  463. and only the number of matches in that line is printed.
  464.  
  465. When this flag is omitted or is set to 0, then it has no effect.
  466.  
  467. --max-columns-preview
  468. When the '--max-columns' flag is used, ripgrep will by default completely
  469. replace any line that is too long with a message indicating that a matching
  470. line was removed. When this flag is combined with '--max-columns', a preview
  471. of the line (corresponding to the limit size) is shown instead, where the part
  472. of the line exceeding the limit is not shown.
  473.  
  474. If the '--max-columns' flag is not set, then this has no effect.
  475.  
  476. This flag can be disabled with '--no-max-columns-preview'.
  477.  
  478. -m, --max-count <NUM>
  479. Limit the number of matching lines per file searched to NUM.
  480.  
  481. --max-depth <NUM>
  482. Limit the depth of directory traversal to NUM levels beyond the paths given. A
  483. value of zero only searches the explicitly given paths themselves.
  484.  
  485. For example, 'rg --max-depth 0 dir/' is a no-op because dir/ will not be
  486. descended into. 'rg --max-depth 1 dir/' will search only the direct children of
  487. 'dir'.
  488.  
  489. --max-filesize <NUM+SUFFIX?>
  490. Ignore files larger than NUM in size. This does not apply to directories.
  491.  
  492. The input format accepts suffixes of K, M or G which correspond to kilobytes,
  493. megabytes and gigabytes, respectively. If no suffix is provided the input is
  494. treated as bytes.
  495.  
  496. Examples: --max-filesize 50K or --max-filesize 80M
  497.  
  498. --mmap
  499. Search using memory maps when possible. This is enabled by default when ripgrep
  500. thinks it will be faster.
  501.  
  502. Memory map searching doesn't currently support all options, so if an
  503. incompatible option (e.g., --context) is given with --mmap, then memory maps
  504. will not be used.
  505.  
  506. Note that ripgrep may abort unexpectedly when --mmap if it searches a file that
  507. is simultaneously truncated.
  508.  
  509. This flag overrides --no-mmap.
  510.  
  511. -U, --multiline
  512. Enable matching across multiple lines.
  513.  
  514. When multiline mode is enabled, ripgrep will lift the restriction that a match
  515. cannot include a line terminator. For example, when multiline mode is not
  516. enabled (the default), then the regex '\p{any}' will match any Unicode
  517. codepoint other than '\n'. Similarly, the regex '\n' is explicitly forbidden,
  518. and if you try to use it, ripgrep will return an error. However, when multiline
  519. mode is enabled, '\p{any}' will match any Unicode codepoint, including '\n',
  520. and regexes like '\n' are permitted.
  521.  
  522. An important caveat is that multiline mode does not change the match semantics
  523. of '.'. Namely, in most regex matchers, a '.' will by default match any
  524. character other than '\n', and this is true in ripgrep as well. In order to
  525. make '.' match '\n', you must enable the "dot all" flag inside the regex.
  526. For example, both '(?s).' and '(?s:.)' have the same semantics, where '.' will
  527. match any character, including '\n'. Alternatively, the '--multiline-dotall'
  528. flag may be passed to make the "dot all" behavior the default. This flag only
  529. applies when multiline search is enabled.
  530.  
  531. There is no limit on the number of the lines that a single match can span.
  532.  
  533. **WARNING**: Because of how the underlying regex engine works, multiline
  534. searches may be slower than normal line-oriented searches, and they may also
  535. use more memory. In particular, when multiline mode is enabled, ripgrep
  536. requires that each file it searches is laid out contiguously in memory
  537. (either by reading it onto the heap or by memory-mapping it). Things that
  538. cannot be memory-mapped (such as stdin) will be consumed until EOF before
  539. searching can begin. In general, ripgrep will only do these things when
  540. necessary. Specifically, if the --multiline flag is provided but the regex
  541. does not contain patterns that would match '\n' characters, then ripgrep
  542. will automatically avoid reading each file into memory before searching it.
  543. Nevertheless, if you only care about matches spanning at most one line, then it
  544. is always better to disable multiline mode.
  545.  
  546. This flag can be disabled with --no-multiline.
  547.  
  548. --multiline-dotall
  549. This flag enables "dot all" in your regex pattern, which causes '.' to match
  550. newlines when multiline searching is enabled. This flag has no effect if
  551. multiline searching isn't enabled with the --multiline flag.
  552.  
  553. Normally, a '.' will match any character except newlines. While this behavior
  554. typically isn't relevant for line-oriented matching (since matches can span at
  555. most one line), this can be useful when searching with the -U/--multiline flag.
  556. By default, the multiline mode runs without this flag.
  557.  
  558. This flag is generally intended to be used in an alias or your ripgrep config
  559. file if you prefer "dot all" semantics by default. Note that regardless of
  560. whether this flag is used, "dot all" semantics can still be controlled via
  561. inline flags in the regex pattern itself, e.g., '(?s:.)' always enables "dot
  562. all" whereas '(?-s:.)' always disables "dot all".
  563.  
  564. This flag can be disabled with --no-multiline-dotall.
  565.  
  566. --no-config
  567. Never read configuration files. When this flag is present, ripgrep will not
  568. respect the RIPGREP_CONFIG_PATH environment variable.
  569.  
  570. If ripgrep ever grows a feature to automatically read configuration files in
  571. pre-defined locations, then this flag will also disable that behavior as well.
  572.  
  573. -I, --no-filename
  574. Never print the file path with the matched lines. This is the default when
  575. ripgrep is explicitly instructed to search one file or stdin.
  576.  
  577. This flag overrides --with-filename.
  578.  
  579. --no-heading
  580. Don't group matches by each file. If --no-heading is provided in addition to
  581. the -H/--with-filename flag, then file paths will be printed as a prefix for
  582. every matched line. This is the default mode when not printing to a terminal.
  583.  
  584. This overrides the --heading flag.
  585.  
  586. --no-ignore
  587. Don't respect ignore files (.gitignore, .ignore, etc.). This implies
  588. --no-ignore-parent, --no-ignore-dot and --no-ignore-vcs.
  589.  
  590. This flag can be disabled with the --ignore flag.
  591.  
  592. --no-ignore-dot
  593. Don't respect .ignore files.
  594.  
  595. This flag can be disabled with the --ignore-dot flag.
  596.  
  597. --no-ignore-global
  598. Don't respect ignore files that come from "global" sources such as git's
  599. `core.excludesFile` configuration option (which defaults to
  600. `$HOME/.config/git/ignore`).
  601.  
  602. This flag can be disabled with the --ignore-global flag.
  603.  
  604. --no-ignore-messages
  605. Suppresses all error messages related to parsing ignore files such as .ignore
  606. or .gitignore.
  607.  
  608. This flag can be disabled with the --ignore-messages flag.
  609.  
  610. --no-ignore-parent
  611. Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories.
  612.  
  613. This flag can be disabled with the --ignore-parent flag.
  614.  
  615. --no-ignore-vcs
  616. Don't respect version control ignore files (.gitignore, etc.). This implies
  617. --no-ignore-parent for VCS files. Note that .ignore files will continue to be
  618. respected.
  619.  
  620. This flag can be disabled with the --ignore-vcs flag.
  621.  
  622. -N, --no-line-number
  623. Suppress line numbers. This is enabled by default when not searching in a
  624. terminal.
  625.  
  626. --no-messages
  627. Suppress all error messages related to opening and reading files. Error
  628. messages related to the syntax of the pattern given are still shown.
  629.  
  630. This flag can be disabled with the --messages flag.
  631.  
  632. --no-mmap
  633. Never use memory maps, even when they might be faster.
  634.  
  635. This flag overrides --mmap.
  636.  
  637. --no-pcre2-unicode
  638. When PCRE2 matching is enabled, this flag will disable Unicode mode, which is
  639. otherwise enabled by default. If PCRE2 matching is not enabled, then this flag
  640. has no effect.
  641.  
  642. When PCRE2's Unicode mode is enabled, several different types of patterns
  643. become Unicode aware. This includes '\b', '\B', '\w', '\W', '\d', '\D',
  644. '\s' and '\S'. Similarly, the '.' meta character will match any Unicode
  645. codepoint instead of any byte. Caseless matching will also use Unicode simple
  646. case folding instead of ASCII-only case insensitivity.
  647.  
  648. Unicode mode in PCRE2 represents a critical trade off in the user experience
  649. of ripgrep. In particular, unlike the default regex engine, PCRE2 does not
  650. support the ability to search possibly invalid UTF-8 with Unicode features
  651. enabled. Instead, PCRE2 *requires* that everything it searches when Unicode
  652. mode is enabled is valid UTF-8. (Or valid UTF-16/UTF-32, but for the purposes
  653. of ripgrep, we only discuss UTF-8.) This means that if you have PCRE2's Unicode
  654. mode enabled and you attempt to search invalid UTF-8, then the search for that
  655. file will halt and print an error. For this reason, when PCRE2's Unicode mode
  656. is enabled, ripgrep will automatically "fix" invalid UTF-8 sequences by
  657. replacing them with the Unicode replacement codepoint.
  658.  
  659. If you would rather see the encoding errors surfaced by PCRE2 when Unicode mode
  660. is enabled, then pass the --no-encoding flag to disable all transcoding.
  661.  
  662. Related flags: --pcre2
  663.  
  664. This flag can be disabled with --pcre2-unicode.
  665.  
  666. -0, --null
  667. Whenever a file path is printed, follow it with a NUL byte. This includes
  668. printing file paths before matches, and when printing a list of matching files
  669. such as with --count, --files-with-matches and --files. This option is useful
  670. for use with xargs.
  671.  
  672. --null-data
  673. Enabling this option causes ripgrep to use NUL as a line terminator instead of
  674. the default of '\n'.
  675.  
  676. This is useful when searching large binary files that would otherwise have very
  677. long lines if '\n' were used as the line terminator. In particular, ripgrep
  678. requires that, at a minimum, each line must fit into memory. Using NUL instead
  679. can be a useful stopgap to keep memory requirements low and avoid OOM (out of
  680. memory) conditions.
  681.  
  682. This is also useful for processing NUL delimited data, such as that emitted
  683. when using ripgrep's -0/--null flag or find's --print0 flag.
  684.  
  685. Using this flag implies -a/--text.
  686.  
  687. --one-file-system
  688. When enabled, ripgrep will not cross file system boundaries relative to where
  689. the search started from.
  690.  
  691. Note that this applies to each path argument given to ripgrep. For example, in
  692. the command 'rg --one-file-system /foo/bar /quux/baz', ripgrep will search both
  693. '/foo/bar' and '/quux/baz' even if they are on different file systems, but will
  694. not cross a file system boundary when traversing each path's directory tree.
  695.  
  696. This is similar to find's '-xdev' or '-mount' flag.
  697.  
  698. This flag can be disabled with --no-one-file-system.
  699.  
  700. -o, --only-matching
  701. Print only the matched (non-empty) parts of a matching line, with each such
  702. part on a separate output line.
  703.  
  704. --passthru
  705. Print both matching and non-matching lines.
  706.  
  707. Another way to achieve a similar effect is by modifying your pattern to match
  708. the empty string. For example, if you are searching using 'rg foo' then using
  709. 'rg "^|foo"' instead will emit every line in every file searched, but only
  710. occurrences of 'foo' will be highlighted. This flag enables the same behavior
  711. without needing to modify the pattern.
  712.  
  713. --path-separator <SEPARATOR>
  714. Set the path separator to use when printing file paths. This defaults to your
  715. platform's path separator, which is / on Unix and \ on Windows. This flag is
  716. intended for overriding the default when the environment demands it (e.g.,
  717. cygwin). A path separator is limited to a single byte.
  718.  
  719. -P, --pcre2
  720. When this flag is present, ripgrep will use the PCRE2 regex engine instead of
  721. its default regex engine.
  722.  
  723. This is generally useful when you want to use features such as look-around
  724. or backreferences.
  725.  
  726. Note that PCRE2 is an optional ripgrep feature. If PCRE2 wasn't included in
  727. your build of ripgrep, then using this flag will result in ripgrep printing
  728. an error message and exiting. PCRE2 may also have worse user experience in
  729. some cases, since it has fewer introspection APIs than ripgrep's default regex
  730. engine. For example, if you use a '
  731. ' in a PCRE2 regex without the
  732. '-U/--multiline' flag, then ripgrep will silently fail to match anything
  733. instead of reporting an error immediately (like it does with the default
  734. regex engine).
  735.  
  736. Related flags: --no-pcre2-unicode
  737.  
  738. This flag can be disabled with --no-pcre2.
  739.  
  740. --pcre2-version
  741. When this flag is present, ripgrep will print the version of PCRE2 in use,
  742. along with other information, and then exit. If PCRE2 is not available, then
  743. ripgrep will print an error message and exit with an error code.
  744.  
  745. --pre <COMMAND>
  746. For each input FILE, search the standard output of COMMAND FILE rather than the
  747. contents of FILE. This option expects the COMMAND program to either be an
  748. absolute path or to be available in your PATH. Either an empty string COMMAND
  749. or the '--no-pre' flag will disable this behavior.
  750.  
  751. WARNING: When this flag is set, ripgrep will unconditionally spawn a
  752. process for every file that is searched. Therefore, this can incur an
  753. unnecessarily large performance penalty if you don't otherwise need the
  754. flexibility offered by this flag. One possible mitigation to this is to use
  755. the '--pre-glob' flag to limit which files a preprocessor is run with.
  756.  
  757. A preprocessor is not run when ripgrep is searching stdin.
  758.  
  759. When searching over sets of files that may require one of several decoders
  760. as preprocessors, COMMAND should be a wrapper program or script which first
  761. classifies FILE based on magic numbers/content or based on the FILE name and
  762. then dispatches to an appropriate preprocessor. Each COMMAND also has its
  763. standard input connected to FILE for convenience.
  764.  
  765. For example, a shell script for COMMAND might look like:
  766.  
  767. case "$1" in
  768. *.pdf)
  769. exec pdftotext "$1" -
  770. ;;
  771. *)
  772. case $(file "$1") in
  773. *Zstandard*)
  774. exec pzstd -cdq
  775. ;;
  776. *)
  777. exec cat
  778. ;;
  779. esac
  780. ;;
  781. esac
  782.  
  783. The above script uses `pdftotext` to convert a PDF file to plain text. For
  784. all other files, the script uses the `file` utility to sniff the type of the
  785. file based on its contents. If it is a compressed file in the Zstandard format,
  786. then `pzstd` is used to decompress the contents to stdout.
  787.  
  788. This overrides the -z/--search-zip flag.
  789.  
  790. --pre-glob <GLOB>...
  791. This flag works in conjunction with the --pre flag. Namely, when one or more
  792. --pre-glob flags are given, then only files that match the given set of globs
  793. will be handed to the command specified by the --pre flag. Any non-matching
  794. files will be searched without using the preprocessor command.
  795.  
  796. This flag is useful when searching many files with the --pre flag. Namely,
  797. it permits the ability to avoid process overhead for files that don't need
  798. preprocessing. For example, given the following shell script, 'pre-pdftotext':
  799.  
  800. #!/bin/sh
  801.  
  802. pdftotext "$1" -
  803.  
  804. then it is possible to use '--pre pre-pdftotext --pre-glob '*.pdf'' to make
  805. it so ripgrep only executes the 'pre-pdftotext' command on files with a '.pdf'
  806. extension.
  807.  
  808. Multiple --pre-glob flags may be used. Globbing rules match .gitignore globs.
  809. Precede a glob with a ! to exclude it.
  810.  
  811. This flag has no effect if the --pre flag is not used.
  812.  
  813. -p, --pretty
  814. This is a convenience alias for '--color always --heading --line-number'. This
  815. flag is useful when you still want pretty output even if you're piping ripgrep
  816. to another program or file. For example: 'rg -p foo | less -R'.
  817.  
  818. -q, --quiet
  819. Do not print anything to stdout. If a match is found in a file, then ripgrep
  820. will stop searching. This is useful when ripgrep is used only for its exit
  821. code (which will be an error if no matches are found).
  822.  
  823. When --files is used, then ripgrep will stop finding files after finding the
  824. first file that matches all ignore rules.
  825.  
  826. --regex-size-limit <NUM+SUFFIX?>
  827. The upper size limit of the compiled regex. The default limit is 10M.
  828.  
  829. The argument accepts the same size suffixes as allowed in the --max-filesize
  830. flag.
  831.  
  832. -e, --regexp <PATTERN>...
  833. A pattern to search for. This option can be provided multiple times, where
  834. all patterns given are searched. Lines matching at least one of the provided
  835. patterns are printed. This flag can also be used when searching for patterns
  836. that start with a dash.
  837.  
  838. For example, to search for the literal '-foo', you can use this flag:
  839.  
  840. rg -e -foo
  841.  
  842. You can also use the special '--' delimiter to indicate that no more flags
  843. will be provided. Namely, the following is equivalent to the above:
  844.  
  845. rg -- -foo
  846.  
  847. -r, --replace <REPLACEMENT_TEXT>
  848. Replace every match with the text given when printing results. Neither this
  849. flag nor any other ripgrep flag will modify your files.
  850.  
  851. Capture group indices (e.g., $5) and names (e.g., $foo) are supported in the
  852. replacement string. In shells such as Bash and zsh, you should wrap the
  853. pattern in single quotes instead of double quotes. Otherwise, capture group
  854. indices will be replaced by expanded shell variables which will most likely
  855. be empty.
  856.  
  857. Note that the replacement by default replaces each match, and NOT the entire
  858. line. To replace the entire line, you should match the entire line.
  859.  
  860. This flag can be used with the -o/--only-matching flag.
  861.  
  862. -z, --search-zip
  863. Search in compressed files. Currently gzip, bzip2, xz, LZ4, LZMA, Brotli and
  864. Zstd files are supported. This option expects the decompression binaries to be
  865. available in your PATH.
  866.  
  867. This flag can be disabled with --no-search-zip.
  868.  
  869. -S, --smart-case
  870. Searches case insensitively if the pattern is all lowercase. Search case
  871. sensitively otherwise.
  872.  
  873. This overrides the -s/--case-sensitive and -i/--ignore-case flags.
  874.  
  875. --sort <SORTBY>
  876. This flag enables sorting of results in ascending order. The possible values
  877. for this flag are:
  878.  
  879. path Sort by file path.
  880. modified Sort by the last modified time on a file.
  881. accessed Sort by the last accessed time on a file.
  882. created Sort by the creation time on a file.
  883. none Do not sort results.
  884.  
  885. If the sorting criteria isn't available on your system (for example, creation
  886. time is not available on ext4 file systems), then ripgrep will attempt to
  887. detect this and print an error without searching any results. Otherwise, the
  888. sort order is unspecified.
  889.  
  890. To sort results in reverse or descending order, use the --sortr flag. Also,
  891. this flag overrides --sortr.
  892.  
  893. Note that sorting results currently always forces ripgrep to abandon
  894. parallelism and run in a single thread.
  895.  
  896. --sortr <SORTBY>
  897. This flag enables sorting of results in descending order. The possible values
  898. for this flag are:
  899.  
  900. path Sort by file path.
  901. modified Sort by the last modified time on a file.
  902. accessed Sort by the last accessed time on a file.
  903. created Sort by the creation time on a file.
  904. none Do not sort results.
  905.  
  906. If the sorting criteria isn't available on your system (for example, creation
  907. time is not available on ext4 file systems), then ripgrep will attempt to
  908. detect this and print an error without searching any results. Otherwise, the
  909. sort order is unspecified.
  910.  
  911. To sort results in ascending order, use the --sort flag. Also, this flag
  912. overrides --sort.
  913.  
  914. Note that sorting results currently always forces ripgrep to abandon
  915. parallelism and run in a single thread.
  916.  
  917. --stats
  918. Print aggregate statistics about this ripgrep search. When this flag is
  919. present, ripgrep will print the following stats to stdout at the end of the
  920. search: number of matched lines, number of files with matches, number of files
  921. searched, and the time taken for the entire search to complete.
  922.  
  923. This set of aggregate statistics may expand over time.
  924.  
  925. Note that this flag has no effect if --files, --files-with-matches or
  926. --files-without-match is passed.
  927.  
  928. This flag can be disabled with --no-stats.
  929.  
  930. -a, --text
  931. Search binary files as if they were text. When this flag is present, ripgrep's
  932. binary file detection is disabled. This means that when a binary file is
  933. searched, its contents may be printed if there is a match. This may cause
  934. escape codes to be printed that alter the behavior of your terminal.
  935.  
  936. When binary file detection is enabled it is imperfect. In general, it uses
  937. a simple heuristic. If a NUL byte is seen during search, then the file is
  938. considered binary and search stops (unless this flag is present).
  939. Alternatively, if the '--binary' flag is used, then ripgrep will only quit
  940. when it sees a NUL byte after it sees a match (or searches the entire file).
  941.  
  942. This flag can be disabled with '--no-text'. It overrides the '--binary' flag.
  943.  
  944. -j, --threads <NUM>
  945. The approximate number of threads to use. A value of 0 (which is the default)
  946. causes ripgrep to choose the thread count using heuristics.
  947.  
  948. --trim
  949. When set, all ASCII whitespace at the beginning of each line printed will be
  950. trimmed.
  951.  
  952. This flag can be disabled with --no-trim.
  953.  
  954. -t, --type <TYPE>...
  955. Only search files matching TYPE. Multiple type flags may be provided. Use the
  956. --type-list flag to list all available types.
  957.  
  958. --type-add <TYPE_SPEC>...
  959. Add a new glob for a particular file type. Only one glob can be added at a
  960. time. Multiple --type-add flags can be provided. Unless --type-clear is used,
  961. globs are added to any existing globs defined inside of ripgrep.
  962.  
  963. Note that this MUST be passed to every invocation of ripgrep. Type settings are
  964. NOT persisted.
  965.  
  966. Example:
  967.  
  968. rg --type-add 'foo:*.foo' -tfoo PATTERN.
  969.  
  970. --type-add can also be used to include rules from other types with the special
  971. include directive. The include directive permits specifying one or more other
  972. type names (separated by a comma) that have been defined and its rules will
  973. automatically be imported into the type specified. For example, to create a
  974. type called src that matches C++, Python and Markdown files, one can use:
  975.  
  976. --type-add 'src:include:cpp,py,md'
  977.  
  978. Additional glob rules can still be added to the src type by using the
  979. --type-add flag again:
  980.  
  981. --type-add 'src:include:cpp,py,md' --type-add 'src:*.foo'
  982.  
  983. Note that type names must consist only of Unicode letters or numbers.
  984. Punctuation characters are not allowed.
  985.  
  986. --type-clear <TYPE>...
  987. Clear the file type globs previously defined for TYPE. This only clears the
  988. default type definitions that are found inside of ripgrep.
  989.  
  990. Note that this MUST be passed to every invocation of ripgrep. Type settings are
  991. NOT persisted.
  992.  
  993. --type-list
  994. Show all supported file types and their corresponding globs.
  995.  
  996. -T, --type-not <TYPE>...
  997. Do not search files matching TYPE. Multiple type-not flags may be provided. Use
  998. the --type-list flag to list all available types.
  999.  
  1000. -u, --unrestricted
  1001. Reduce the level of "smart" searching. A single -u won't respect .gitignore
  1002. (etc.) files. Two -u flags will additionally search hidden files and
  1003. directories. Three -u flags will additionally search binary files.
  1004.  
  1005. 'rg -uuu' is roughly equivalent to 'grep -r'.
  1006.  
  1007. -V, --version
  1008. Prints version information
  1009.  
  1010. --vimgrep
  1011. Show results with every match on its own line, including line numbers and
  1012. column numbers. With this option, a line with more than one match will be
  1013. printed more than once.
  1014.  
  1015. -H, --with-filename
  1016. Display the file path for matches. This is the default when more than one
  1017. file is searched. If --heading is enabled (the default when printing to a
  1018. terminal), the file path will be shown above clusters of matches from each
  1019. file; otherwise, the file name will be shown as a prefix for each matched line.
  1020.  
  1021. This flag overrides --no-filename.
  1022.  
  1023. -w, --word-regexp
  1024. Only show matches surrounded by word boundaries. This is roughly equivalent to
  1025. putting \b before and after all of the search patterns.
  1026.  
  1027. This overrides the --line-regexp flag.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement