ripgrep

ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern.

ripgrep 采用 Rust 编写,速度很快.

查看帮助:

  1. rg -h

查看手册:

  1. man rg

安装

  1. pacman -S ripgrep

用法

快速入门

1. 搜索字符串

在当前文件夹中递归搜索字符串 hello

  1. rg hello

rg 会以 文件全路径 + 字符串所在行 的方式展示所有的匹配项.

忽略大小写:

  1. rg -i hello

只列出文件全路径:

  1. rg -il hello

2. 搜索特定类型文件

搜索包含字符串 hellocpp 文件:

  1. rg -tcpp hello

搜索包含字符串 hellomarkdown 文件:

  1. rg -tmd hello

3. 删除指定文件

可以用正则表达式匹配一类文件。

删除文件夹中如下的文件:

  1. 0b28c491-5908-4f0e-82bf-0ca59386e6f1
  2. 1badb021-1142-4494-8a88-3df730c807e2

可以用正则表示为:[a-f0-9]{8}-

  1. ls | rg -e [a-f0-9]{8}- | xargs rm