前文我们详细阐述了 find 命令的基本操作 帮你精通Linux:Find命令的八大属性 以及 find 命令的的高阶操作 帮你精通Linux:Find命令高阶操作4项动作 。然而,我们日用的高频查询往往极其简单,调用 find 命令颇为繁琐,此时我们需要 riggrep 的帮助。
riggrep - recursively search current directory for lines matching a pattern
基本的操作命令为:
rg -options pattern path
其中遍历搜索“二进制文件”:
rg -uuu 与 grep -r 等效
首先,通过 tldr 快速查看帮助:
ripgrep
A recursive line-oriented CLI search tool.Aims to be a faster alternative to grep.More information: https://github.com/BurntSushi/ripgrep.
- Recursively search the current directory for a regex pattern:
rg {{pattern}}
- Search for pattern including all .gitignored and hidden files:
rg -uu {{pattern}}
- Search for a pattern only in a certain filetype (e.g., html, css, etc.):
rg -t {{filetype}} {{pattern}}
- Search for a pattern only in a subset of directories:
rg {{pattern}} {{set_of_subdirs}}
- Search for a pattern in files matching a glob (e.g., README.*):
rg {{pattern}} -g {{glob}}
- Only list matched files (useful when piping to other commands):
rg --files-with-matches {{pattern}}
- Show lines that do not match the given pattern:
rg --invert-match {{pattern}}
- Search a literal string pattern:
rg -F {{string}}
其次,通过起内建的 help :
➜ Public rg --help | tail
file; otherwise, the file name will be shown as a prefix for each matched line.
This flag overrides --no-filename.
-w, --word-regexp
Only show matches surrounded by word boundaries. This is roughly equivalent to
putting b before and after all of the search patterns.
This overrides the --line-regexp flag.
最后通过 manual 查阅:
列出含有关键词的所有文件:
➜ Public rg -il javascript | head
Centuar-Emacs/README.md
JS-for-Data/04.objects-and-classes.org
Definitive-JavaScript/01.Types.Values.Variables.org
Definitive-JavaScript/02.Expressions.org
Definitive-JavaScript/03.Statements.org
Definitive-JavaScript/04.Objects.org
Definitive-JavaScript/05.Array.org
Definitive-JavaScript/09.classes.org
Definitive-JavaScript/08.function.org
Definitive-JavaScript/10.modules.org
其中短写的 -l 为 “-l, --files-with-matches”
以及反向搜索:
rg --invert-match {{pattern}}
最后是只搜索指定的文件类型:
rg -t {{filetype}} {{pattern}}
页面更新:2024-04-04
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号