Ripgrep is a command-line search tool. Developed using Rust, Ripgrep can run on multiple platforms, such as Mac, Linux, and Windows. RipGrep has similar functions to The Silver Searcher, Ack, and GNU Grep. RipGrep is officially claimed to be N times faster than other similar search tools. VSCode also uses RipGrep as its search tool by default since version 1.11.

The address of the project: https://github.com/BurntSushi/ripgrep

Features supported by Ripgrep

  • Automatic recursive search (grep requires -r).

  • Automatically ignores files in.gitignore as well as binary and hidden files.

  • You can search for specified file types, such as rg-tpy foo, which restricts the search to Python files, and rg-tjs foo, which excludes JS files.

  • Most Grep features are supported, such as displaying the context of search results, supporting multiple pattern searches, highlighting matching search results, and supporting Unicode.

  • Supports various text encoding formats, such as UTF-8, UTF-16, Latin-1, GBK, EUC-JP, Shift_JIS, and so on.

  • Supports search for compressed files in common formats, such as gzip, Xz, LZMA, bzip2, and LZ4.

  • Automatically highlight matching results.

Ripgrep official performance benchmark test result

  • Search the entire Linux kernel source code

Tool Command Line count Time
ripgrep (Unicode) rg -n -w '[A-Z]+_SUSPEND' 450 0.106 s
git grep LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND' 450 0.553 s
The Silver Searcher ag -w '[A-Z]+_SUSPEND' 450 0.589 s
git grep (Unicode) LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND' 450 2.266 s
sift sift --git -n -w '[A-Z]+_SUSPEND' 450 3.505 s
ack ack -w '[A-Z]+_SUSPEND' 1878 6.823 s
The Platinum Searcher pt -w -e '[A-Z]+_SUSPEND' 450 14.208 s
Tool Command Line count Time
ripgrep rg -L -u -tc -n -w '[A-Z]+_SUSPEND' 404 0.079 s
ucg ucg --type=cc -w '[A-Z]+_SUSPEND' 390 0.163 s
GNU grep egrep -R -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND' 404 0.611 s
  • Compare Ripgrep with GNU Grep in a single large file. The file size is about 9.3 GB.

Tool Command Line count Time
ripgrep rg -w 'Sherlock [A-Z]\w+' 5268 2.108 s
GNU grep LC_ALL=C egrep -w 'Sherlock [A-Z]\w+' 5268 7.014 s

Ripgrep rendering

Install Ripgrep

Ripgrep is cross-platform and can be installed on Linux, macOS, and Windows. The binary version of each platform is provided. The following uses Linux as an example to install the binary version.

Wget $$at https://github.com/BurntSushi/ripgrep/releases/download/0.10.0/ripgrep-0.10.0-x86_64-unknown-linux-musl.tar.gz Tar XZVF ripgrep 0.10.0-x86_64-unknown-linux-musl.tar.gz $cp ripgrep 0.10.0-x86_64-unknown-linux-musl/rg /usr/local/bin/Copy the code

If you use other platforms, the approach is similar. You can download the corresponding version from the official download page according to the actual situation. Of course, the official also provides a variety of other installation methods, please refer to the official installation documentation.

Ripgrep syntax format

  • Overall syntax format

USAGE: rg [OPTIONS] PATTERN [PATH ...]  rg [OPTIONS] [-e PATTERN ...]  [-f PATTERNFILE ...]  [PATH ...]  rg [OPTIONS] --files [PATH ...]  rg [OPTIONS] --type-list command | rg [OPTIONS] PATTERN ARGS: <PATTERN> A regular expression used for searching. To match a pattern beginning with a dash, use the -e/--regexp flag. For example, to search for the literal '-foo', you can use this flag: 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 <PATH>... A file or directory to search. Directories are searched recursively. Paths specified on the command line override glob and ignore rules.Copy the code
  • Supported command line options

Here are some common options.

options instructions note
-A, –after-context <NUM> After the match is displayed<NUM>Line. overwrite--contextOptions.
-B, –before-context <NUM> Before displaying the matching content<NUM>Line. overwrite--contextOptions.
-b, –byte-offset Displays the byte offset of the matching content in the file. and-oOnly offsets are printed when used together.
-s, –case-sensitive Enable case sensitivity. overwrite-i(--ignore case)  和 -S(--smart case)Options.
–color <WHEN> When to use color. The default value is auto. Possible values are never, auto, always, and ANSI. if--vimgreThe default value is never if the option is used.
–column Displays the number of matching columns (starting from 1). If the column number is not displayed, it is available--no-columnCancel.
-C, –context <NUM> Displays the preceding and following matches<NUM>Line. This option overrides-B  和 -AOptions.
–context-separator <SEPARATOR> Separate noncontiguous output lines in the output result. You can use\x7F  或 \tThe default is--.
-c, –count Only the total number of rows that match results is displayed. If only one file is given to Ripgrep, only the total number of matching lines is printed. You can use--with-filenameTo force the file name to be printed. This option overrides--count-matchesOptions.
–count-matches Only the total number of matches is displayed. You can use--with-filenameTo force the output of a filename even if there is only one file.
–debug Displays debugging information.
–dfa-size-limit <NUM+SUFFIX? > Specifies the upper limit of regular expression DFA. The default value is 10M. This option allows you to accept and--max-filesizeSuffix logo of the same size.
-E, –encoding <ENCODING> Specifies the text encoding format. The default is auto. More coding format reference: https://encoding.spec.whatwg.org/#concept-encoding-get
-f, –file <PATTERNFILE>. Read the search pattern from the file, one pattern per line. In combination with-e/--regexpParameters can be combined with multiple files, and all combinations will be matched.
–files Prints all file paths to be searched. In order torg <options> --files [PATH...]The search mode cannot be added.
-l, –files-with-matches Only file names that match are printed. This option overrides--files-without-match.
–files-without-match Only file names that do not match are printed. This option overrides--file-with-matches.
-F, –fixed-strings Think of search patterns as regular text rather than regular expressions. This option is available--no-fixed-stringsTo ban.
-L, –follow This option recursively searches for symbolic links and is turned off by default. This option is available--no-followOption to manually close.
-g, –glob <GLOB>. Include or exclude files and directories that match a given search, can be used! To pick up. This option can be used multiple times and matches the rules in.gitignore.
-h, –help Print help information.
–heading Print the file name above the matching content instead of on the same line. This option is enabled by default and can be used--no-headingTo shut down.
–hidden Enable search for hidden files and folders. Search for hidden files and folders is ignored by default, available--no-hiddenTo shut down.
–iglob <GLOB>. Work with--glob, but this option is case insensitive.
-i, –ignore-case Specifies that the search mode is case insensitive. This option will be selected by-s/--case-sensitive  或 -S/--smart-caseCoverage.
–ignore-file <PATH>. Specifies the path to be ignored during the search. The format is the same.gitignore, you can specify more than one. If there are multiple--ignore-fileWhen marked, the subsequent priority is higher.
-v, –invert-match Reverse matching, showing rows that do not match a given pattern.
-n, –line-number Displays the number of lines in the file that matches the content. This option is turned on by default.
-x, –line-regexp Only rows whose entire row matches the search pattern are displayed. This option overrides--word-regexp.
-M, –max-columns <NUM> Do not print longer than<NUM>Only the matching number of the line is displayed.
-m, –max-count <NUM> Limit the maximum number of files<NUM>Rows are matched.
–max-depth <NUM> Limit the recursive search depth of folders. Such as:rg --max-depth 0 dir/It indicates that no search is performed.
–max-filesize <NUM+SUFFIX? > Ignore greater than when searching<NUM>Byte file. SUFFIX can be in K, M, or G, and the default is byte.
–mmap Try to use Memory Maps for your search, which will be faster. This option is the default behavior. If you are using--mmapWhen searching for files, Ripgrep stops unexpectedly--no-mmapOption to turn it off.
–no-config The configuration file is not read and the RIPGREP_CONFIG_PATH variable is ignored.
–no-filename Do not print the names of matching files.
–no-heading Instead of printing the file name above each matching line, print it on the same line as the matching line.
–no-ignore Do not read ignored files, such as.gitignore,.ignore, etc. This option is available--ignoreShut down.
–no-ignore-global Global ignore files are not read, such as:$HOME/.config/git/ignore. This option is available--ignore-globalShut down.
–no-ignore-messages Cancel parsing error messages in. Ignroe and. Gitignore files. This option can be passed--ignore-messagesShut down.
–no-ignore-parent Do not read.gitignore,.ignore files in parent folder. This option can be passed--ignore-parentShut down.
–no-ignore-vcs The.ignore file in the version controller is not read. This option can be passed--ignore-vcsShut down.
-N, –no-line-number No matching lines are printed.
–no-messages Does not print error messages related to opening and reading files.
-0, –null Appends a NUL character to the printed file path. This is very useful when used with Xargs.
-o, –only-matching Print only matches, not entire lines.
–passthru Print both matched and mismatched lines in the file.
–path-separator <SEPARATOR> The path separator, which defaults to/on Linux and \ on Windows.
–pre <COMMAND> with<COMMAND>After the file is processed, the result is passed to Ripgrep. This option has a performance cost.
-p, –pretty This option is--color always --heading --line-numberThe alias.
-q, –quiet This option is not printed to standard output and the search is stopped if a match is found. This option is useful when RipGrep is used in exit code.
–regex-size-limit <NUM+SUFFIX? > Sets the upper limit of compiled regular expressions. The default limit is 10M.
-e, –regexp <PATTERN>. Use the re to match the search criteria. This option can be used multiple times to print lines that match any pattern.
-r, –replace <REPLACEMENT_TEXT> Print it out with the corresponding file content instead of the matching content.
-z, –search-zip Gz, bZ2, Xz, LZMA, and LZ4 file types. This option can be passed--no-search-zipShut down.
-S, –smart-case If it is all lowercase, it is case-insensitive; otherwise, it is case-sensitive. This option can be passed-s/--case-sensitive  和 -i/--ignore-caseTo shut down.
–sort <SORTBY> Sort the output in ascending order. The sorting types are PATH, Modified, email exchange, and created.
–sortr <SORTBY> Sort the output results in descending order, including path, Modified, email exchange, and created.
–stats Print statistical results.
-a, –text Search binaries. This option can be passed--no-textShut down.
-j, –threads <NUM> The number of threads to use when searching.
-t, –type <TYPE>. Only the specified file type is searched. Can be achieved by--type-listTo list the supported file types.
–type-add <TYPE_SPEC>. Add a file type.
–type-clear <TYPE>. Clear the default file type.
–type-list Lists all built-in file types.
-T, –type-not <TYPE>. Do not search for certain file types.
-u, –unrestricted -uSearch for files in.gitignore,-uuSearch for hidden files,-uuuSearch binaries.
-V, –version Print version information.
–vimgrep A single line is printed for each match, or multiple lines if there are more than one match.
-H, –with-filename Prints the matching file path. This option is turned on by default. This option can be passed--no-filenameShut down.
-w, –word-regexp Match the search parameters as individual words. This option overrides--line-regexpOptions.

For more command-line options, see rg –help for yourself.

Ripgrep Example

Searches the contents of a specified file that contain the keyword

$rg 'github.com' README. Md 1:<h1 align="center"><a title="New «NexT» 6.0.0 version [Reloaded]" href="https://github.com/theme-next/hexo-theme-next">NexT</a></h1>6:[! [mnt-image]](https://github.com/theme-next/hexo-theme-next)21:More NexT examples [here](https://github.com/iissnan/hexo-theme-next/issues/119). 41: $ curl -s https://api.github.com/repos/iissnan/hexo-theme-next/releases/latest | grep tarball_url | cut -d '"' -f 4 | wget -i - -O- | tar -zx -C themes/next --strip-components=1 51: https://api.github.com/repos/iissnan/hexo-theme-next/tarball/v5.1.2 | $curl - L tar - ZXV - C themes/next - strip - components = 1 57: $git clone - branch v5.1.2 themes/next 67 https://github.com/iissnan/hexo-theme-next: $ curl -L https://api.github.com/repos/iissnan/hexo-theme-next/tarball | tar -zxv -C themes/next --strip-components=1 73: $ git clone https://github.com/iissnan/hexo-theme-next themes/next 110:For those who also encounter **Error: Cannot find module 'hexo-util'** [issue](https://github.com/iissnan/hexo-theme-next/issues/1490), please check your NPM version. 128:### Theme configurations using Hexo data files ([#328](https://github.com/iissnan/hexo-theme-next/issues/328))282:NexT uses [Tomorrow Theme](https://github.com/chriskempson/tomorrow-theme) with 5 themes for you to choose from. 288:Head over to [Tomorrow Theme](https://github.com/chriskempson/tomorrow-theme) for more details. 367:[download-latest-url]: https://github.com/iissnan/hexo-theme-next/archive/master.zip 368:[releases-latest-url]: https://github.com/iissnan/hexo-theme-next/releases/latest 369:[releases-url]: https://github.com/iissnan/hexo-theme-next/releases 370:[tags-url]: https://github.com/iissnan/hexo-theme-next/tags 371:[commits-url]: https://github.com/iissnan/hexo-theme-next/commits/masterCopy the code

Searches for the content of a specified file that contains a word beginning with a keyword

$ rg 'lang\w+' README.md
154:### Multiple languages support, including:168:Default language is English.
171:language: en
172:# language: zh-Hans173:# language: zh-hk174:# language: zh-tw175:# language: ru176:# language: fr-FR177:# language: de178:# language: ja179:# language: id180:# language: pt181:# language: pt-BRCopy the code

Searches for specified files that contain content beginning with a keyword

$rg 'hexo\w*' README. Md 1:<h1 align="center"><a title="New «NexT» 6.0.0 version [Reloaded]" href="https://github.com/theme-next/hexo-theme-next">NexT</a></h1>3:<p align="center">NexT is a high quality elegant <a href="http://hexo.io">Hexo</a> theme. It is crafted from scratch, with love.</p>6:[! [mnt-image]](https://github.com/theme-next/hexo-theme-next)9:[! [hexo-image]][hexo-url]21:More NexT examples [here](https://github.com/iissnan/hexo-theme-next/issues/119). 25:**1.** Change dir to **hexo root** directory. There must be `node_modules`, `source`, `themes` and other directories: 27: $ cd hexo 41: $ curl -s https://api.github.com/repos/iissnan/hexo-theme-next/releases/latest | grep tarball_url | cut -d '"' -f 4 | wget -i - -O- | tar -zx -C themes/next --strip-components=1 51: https://api.github.com/repos/iissnan/hexo-theme-next/tarball/v5.1.2 | $curl - L tar - ZXV - C themes/next - strip - components = 1 57: $git clone - branch v5.1.2 https://github.com/iissnan/hexo-theme-next themes/nextCopy the code

Searches for contents containing keywords in specified directories and subheadings

$ rg 'github.com' ./
./src/scrollspy.js
6:* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)./src/affix.js
6: * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)./src/js.cookie.js
3: * https://github.com/js-cookie/js-cookieCopy the code

Search for content with keywords as separate words

$ rg -w 'github.com' ./ ./bower.json 36: "url" : "http://github.com/julianshapiro/velocity.git"./velocity.ui.js 58: var abortError = "Velocity UI Pack: You need to update Velocity (jquery.velocity.js) to a newer version. Visit http://github.com/julianshapiro/velocity."; ./velocity.js 442: /* IE detection. Gist: https://gist.github.com/julianshapiro/9098609 */ 463: /* rAF shim. Gist: https://gist.github.com/julianshapiro/9497513 */ 472: /* Technique by Erik Moller. MIT license: https://gist.github.com/paulirish/1579671 */ 480: /* Array compacting. Copyright Lo-Dash. MIT License: https://github.com/lodash/lodash/blob/master/LICENSE.txt */ 522: /* Copyright Martin Bohm. MIT License: https://gist.github.com/Tomalak/818a78a226a0738eaade */Copy the code

Search for files that contain keyword content and print only file names

$ rg -w 'github.com' ./ -l
./velocity.js
./bower.json
./velocity.ui.js
./velocity.ui.min.jsCopy the code

Searches for contents containing keywords in files whose file type format is JS

RipGrep can be implemented in various ways. The following two methods are commonly used.

  • First: specify the file type with the –type option.

$ rg 'function writeOnCanvas' --type js
source/lib/Han/dist/han.js
1726:function writeOnCanvas( text, font ) {Copy the code
  • Second: use the –glob option to wildcard the desired file type.

$ rg  'function writeOnCanvas' -g '*.js'source/lib/Han/dist/han.js
1726:function writeOnCanvas( text, font ) {Copy the code

If you want to search for multiple file types at the same time, you can write it as follows.

$ rg 'Hanzi' -g '*.{js,css}'han.min.js
2:/*! Han.css: the CSS typography framework optimised for Hanzi */

han.js
3: * Han.css: the CSS typography framework optimised for Hanzi
48:  // Address Hanzi and Western script mixed spacing
426:    /* Hanzi and Western mixed spacing 

han.css
4:/*! Han.css: the CSS typography framework optimised for Hanzi */

han.min.css
4:/*! Han.css: the CSS typography framework optimised for Hanzi */Copy the code

Search for content containing keywords in files that do not contain CSS file types under the current table

$ rg 'revertVowel' --type-not css source/lib/Han/dist/han.min.js(this["comb-liga-zhuyin"]=O.substZhuyinCombLiga(this.context)),this},revertVowelCombLiga:f unction(){try{this["comb-liga-vowel"].revert("all")}catch(a){}return this},revertVowelICombLiga:function(){try{this["comb-liga-vowel-i"].revert("all")}catch(a){}return this},revertZhuyinCombLiga:function(){try{this["comb-liga-zhuyin"].revert("all")}catch(a){}return this},revertCombLigaWithPUA:function(){try{this["comb-liga-vowel"].revert("all"),this["comb-liga-vowel-i"].revert("all") ,this["comb-liga-zhuyin"].revert("all")}catch(a){}return this},substInaccurateChar:function(){return this["inaccurate-char"]=O.substInaccurateChar(this.context),this},revertInaccurateChar:function(){try{this["inaccurate-c har"].revert("all")}catch(a){}return this}}),a.addEventListener("DOMContentLoaded",function(){var a; K.classList.contains("han-init")? O.init():(a=J.querySelector(".han-init-context"))&&(O.init=O(a).render())}),("undefined"==typeof b||b===! 1)&&(a.Han=O),O}); source/lib/Han/dist/han.js 2939: revertVowelCombLiga: function() {2946: revertVowelICombLiga: function() {Copy the code

You can also achieve the same effect by writing more succinctly below.

$ rg 'revertVowel' -TcssCopy the code

Use regular expressions for keyword search

$ rg -e "noConf.*lict" ./
./js.cookie.js
21:     api.noConflict = function () {./scrollspy.js
166:  $.fn.scrollspy.noConflict = function () {./affix.js
139:  $.fn.affix.noConflict = function () {Copy the code

Searches for content matching the keyword and displays two lines above and two lines below it

$ rg -e "noConf.*lict" -C2 js.cookie.js 19- var OldCookies = window.Cookies; 20- var api = window.Cookies = factory(); 21: api.noConflict = function () {22- window.Cookies = OldCookies; 23- return api; scrollspy.js 164- // =====================165- 166: $.fn.scrollspy.noConflict = function () {167- $.fn.scrollspy = old 168- return this affix.js 137- // =================138- 139: $.fn.affix.noConflict = function () {140- $.fn.affix = old 141- return thisCopy the code

Search for content that does not contain keywords

$ rg -v "hexo" merge-configs.js 2: 3:var merge = require('./merge'); 4: 5:/** 8: */ 12: if ( data && data.next ) {13: if ( data.next.override ) {15: } else {17: }18: }19: }20:}); 21:30:});Copy the code

Search for keywords and display only the content of the keyword section

$ rg -e "hexo.*warn" -o ./
./tags/lazy-image.js
12:hexo.log.warn

./merge-configs.js
23:hexo.log.warn
24:hexo.log.warn
25:hexo.log.warn
26:hexo.log.warn
27:hexo.log.warn
28:hexo.log.warn
29:hexo.log.warn

./tags/button.js
13:hexo.log.warn

./tags/full-image.js
12:hexo.log.warnCopy the code

Searches for keywords and ignores keyword case content

$ rg -ie "Return.*" merge.js
103:var root = freeGlobal || freeSelf || Function('return this')();
120:    return freeProcess && freeProcess.binding('util');
134: * @returns {Object} Returns `map`.
137:  // Don't return `map.set` because it's not chainable in IE 11.
139:  return map;
148: * @returns {Object} Returns `set`.
151:  // Don't return `set.add` because it's not chainable in IE 11.Copy the code

Search keywords as constant characters

If the keyword contains characters like.(){}*+, you do not need to manually escape the keyword.

$ rg -F "i++)" ./
./tags/exturl.js
27:  for (; i < len; i++) {./tags/group-pictures.js
795:    for (var i = 0; i < rows; i++) {805:    for (var i = 0; i < rows.length; i++) {825:    for (var i = 0; i < pictures.length; i++) {Copy the code

When searching for a character that begins with -, use — as the delimiter.

$ rg -- -1 merge.js
190:  var index = -1,
210:  var index = -1,
233:  var index = -1,
255:  var index = -1,
317:  var index = -1,
348:  var index = -1,
435:  var index = -1,
533:  var index = -1,
605:  return assocIndexOf(this.__data__, key) > -1;
645:  var index = -1,
889: * @returns {number} Returns the index of the matched value, else `-1`.
898:  return -1;Copy the code

Or you can use the -e argument for a similar purpose.

$ rg -e "-1" source/js source/js/src/js.cookie.js 113: cookie = cookie.slice(1, -1); 155: expires: -1 source/js/src/motion.js 190: cursor: -1, 223: getMistLineSettings($logoLineBottom, '-100%')Copy the code

Prints a list of all files under the current list that will be searched

$ rg --files
merge.js
merge-configs.js
tags/lazy-image.js
tags/center-quote.js
tags/tabs.js
tags/note.js
tags/button.js
tags/full-image.js
tags/group-pictures.js
tags/label.js
tags/exturl.jsCopy the code

Outputs all built-in recognizable file types

$ rg --type-list
agda: *.agda, *.lagda
aidl: *.aidl
amake: *.bp, *.mk
asciidoc: *.adoc, *.asc, *.asciidoc
asm: *.S, *.asm, *.s
ats: *.ats, *.dats, *.hats, *.sats
avro: *.avdl, *.avpr, *.avsc
awk: *.awk
bazel: *.bzl, BUILD, WORKSPACE
bitbake: *.bb, *.bbappend, *.bbclass, *.conf, *.inc
bzip2: *.bz2
c: *.H, *.c, *.cats, *.h
cabal: *.cabal
cbor: *.cbor
ceylon: *.ceylon
clojure: *.clj, *.cljc, *.cljs, *.cljx
cmake: *.cmake, CMakeLists.txt
coffeescript: *.coffee
config: *.cfg, *.conf, *.config, *.ini
cpp: *.C, *.H, *.cc, *.cpp, *.cxx, *.h, *.hh, *.hpp, *.hxx, *.inl
creole: *.creole
crystal: *.cr, Projectfile
cs: *.cs
......Copy the code

User-defined search file types

By default, Ripgrep comes with a bunch of predefined types. Typically, these types correspond to well-known common formats. You can also define your own types, for example: you might often search for Web-type files, which contain files of Javascript, HTML, and CSS types.

$ rg --type-add 'web:*.html' --type-add 'web:*.css' --type-add 'web:*.js' -tweb display
han.css
28:  display: block;
34:  display: inline-block;
37:  display: none;
45:  display: none;
174:  display: table; /* 1 */

han.js
442:    // The feature displays the following characters
446:    'display-as': {
1732:  canvas.style.display = 'none'Copy the code

Or you could just write it as

$ rg --type-add 'web:*.{html,css,js}' -tweb displayCopy the code

It is important to note, however, that the Web-type files added above are temporary and only valid for the current command. If you need to use a custom file type for a long time, you can add an alias to automatically add the corresponding file type each time you run RipGrep.

$ alias rg="rg --type-add 'web:*.{html,css,js}'"Copy the code

Of course, there is another way to achieve a similar goal, which is to use the RipGrep configuration file, which defaults to $HOME/. Ripgreprc.

$ cat $HOME/.ripgreprc# Don't let ripgrep vomit really long lines to my terminal.--max-columns=150# Add my 'web' type.--type-add web:*.{html,css,js}*# Using glob patterns to include/exclude files or folders--glob=! git/*# or--glob! git/*# Set the colors.--colors=line:none --colors=line:style:bold# Because who cares about case! ? --smart-caseCopy the code

Replace content containing keywords in the search results

RipGrep provides a function to directly replace keywords during search. Here is an example of changing lowercase letters to uppercase letters in some keywords.

$ rg browse README.md --replace Browse 305:# can be any image format supported by web Browsers (JPEG,PNG,GIF,SVG,..) 322:! [Browser-image]324:[! [Browser Stack](.github/Browserstack_logo.png)](https://www.Browserstack.com/)325:>**BrowserStack** is a cloud-based cross-Browser testing tool that enables developers to test their websites across various Browsers on different operating  systems and mobile devices, without requiring users to install virtual machines, devices or emulators. 343:[Browser-image]: https://img.shields.io/badge/Browser-%20chrome%20%7C%20firefox%20%7C%20opera%20%7C%20safari%20%7C%20ie%20%3E%3D%209-ligh tgrey.svg 344:[Browser-url]: https://www.Browserstack.comCopy the code

The above result is essentially just a substitution in standard output and does not modify the actual file. If you need to make changes to the actual file, you can use the Sed command to do so.

  • If you use GNU Sed (CentOS, Ubuntu, and other Linux distributions), you can use the following command.

$ rg browse --files-with-matches | xargs sed -i 's/browse/Browse/g'Copy the code
  • If you are using BSD Sed (macOS and FreeBSD), you must change the above command to the following command.

$ rg browse --files-with-matches | xargs sed -i '' 's/browse/Browse/g'Copy the code

The -i flag in BSD Sed requires a file extension to back up all modified files. Specifying an empty string prevents file backups.

  • If your file path contains Spaces, you need to separate the file path with the NUL terminator. Here you need to use the -0 argument to tell Ripgrep to print NUL bytes between each path and to tell Xargs to read the NUL byte separated path.

$ rg Browse --files-with-matches -0 | xargs -0 sed -i '' 's/Browse/browse/g'Copy the code

Search the contents containing the keyword directly in the compressed file

Ripgrep supports only the gzip, bzip2, lzma, LZ4, and Xz compression formats, and the corresponding gzip, bzip2, and XZ packages must be installed on the system. In other words, Ripgrep is unmixed through Shelling to another process.

$ rg -z license UNLICENSE.gz
24:For more information, please refer to <http://unlicense.org/>Copy the code

Ripgrep currently does not search for archive formats and therefore skips *.tar.gz files.

Automatic completion function

The binary package provided by RipGrep provides SHELL auto-completion by default. You only need to place the package in the corresponding directory according to the SHELL.

  • Bash 

$mv rg.bash $XDG_CONFIG_HOME/bash_completion/ or $mv rg.bash /etc/bash_completion.d/Copy the code
  • ZSH

$ mv _rg $fpath/Copy the code
  • Fish

$ mv rg.fish $HOME/.config/fish/completions/Copy the code

Reference documentation

http://www.google.comhttp://t.cn/ROI5tMvhttp://t.cn/Rs3caWWhttp://t.cn/Rs3F6Ty

Today’s idea

Gradually found that the sky is purest after a heavy rain. Cold open drink more clean, cry tears of the most bright eyes, after the pain of the idea more mature. Life, is all the way, all the way to lose, also all the way to own. We are stumbling, covered with scars, slowly become a better person.

— A zen little Monk

Recommended reading

  • Diagram of Docker architecture

  • Illustrates the Kubernetes architecture

  • Rapid deployment of Ingress using Helm

  • Use TC and Netem to simulate network exceptions

  • A recommended search tool, FD, is 10 times faster than Find