ripgrep
ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern.
ripgrep 采用 Rust 编写,速度很快.
查看帮助:
rg -h
查看手册:
man rg
安装
pacman -S ripgrep
用法
快速入门
1. 搜索字符串
在当前文件夹中递归搜索字符串 hello
rg hello
rg 会以 文件全路径 + 字符串所在行 的方式展示所有的匹配项.
忽略大小写:
rg -i hello
只列出文件全路径:
rg -il hello
2. 搜索特定类型文件
搜索包含字符串 hello 的 cpp 文件:
rg -tcpp hello
搜索包含字符串 hello 的 markdown 文件:
rg -tmd hello
3. 删除指定文件
可以用正则表达式匹配一类文件。
删除文件夹中如下的文件:
0b28c491-5908-4f0e-82bf-0ca59386e6f11badb021-1142-4494-8a88-3df730c807e2
可以用正则表示为:[a-f0-9]{8}-
ls | rg -e [a-f0-9]{8}- | xargs rm
