一个比grep,ack 更快的命令工具
一:安装部署
apt-get install silversearcher-agroot@uk8s:/etc/apt# which ag
root@uk8s:/etc/apt# apt-get install silversearcher-ag
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
下列【新】软件包将被安装:
silversearcher-ag
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 6 个软件包未被升级。
需要下载 40.1 kB 的归档。
解压缩后会消耗 131 kB 的额外空间。
获取:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 silversearcher-ag amd64 2.2.0-1 [40.1 kB]
已下载 40.1 kB,耗时 0秒 (158 kB/s)
正在选中未选择的软件包 silversearcher-ag。
(正在读取数据库 ... 系统当前共安装有 124727 个文件和目录。)
准备解压 .../silversearcher-ag_2.2.0-1_amd64.deb ...
正在解压 silversearcher-ag (2.2.0-1) ...
正在设置 silversearcher-ag (2.2.0-1) ...
正在处理用于 man-db (2.10.2-1) 的触发器 ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
二:使用
1)搜索默认带行号输出
root@uk8s:/etc/apt# ag a sources.list
1:deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
2:deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
4:deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
5:deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
7:deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
8:deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
10:deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
11:deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
2)与ack 比较
root@uk8s:/etc/apt# time ack a sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
real 0m0.049s
user 0m0.041s
sys 0m0.008s
root@uk8s:/etc/apt# time ag a sources.list
1:deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
2:deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
4:deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
5:deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
7:deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
8:deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
10:deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
11:deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
real 0m0.008s
user 0m0.004s
sys 0m0.002s
比ack更快的代码搜索工具
参数:
-i --ignore-case 忽略大小写-l --files-with-matches 只打印内容匹配的文件的文件名-L --files-without-matches 只打印内容不匹配的文件的文件名-o --only-matching 只打印匹配的内容,不是一整行-G --file-search-regex 只搜索文件名匹配的文件-g 打印文件名匹配的文件名