55
66## 安装
77
8- ``` bash
8+ ``` shell
99# ubuntu下要安装ack-grep,因为在debian系中,ack这个名字被其他的软件占用了。
1010sudo apt-get install ack-grep
1111# alpine Linux-apk软件包管理器 安装 ack
@@ -16,7 +16,7 @@ apk install ack
1616
1717这些参数在linux上的适用频率是相当高的,尤其是你用vim做为IDE的话
1818
19- ```
19+ ``` shell
2020-c(统记)/ -i(忽略大小)/ -h(不显示名称)/
2121-l(只显文件名)/ -n(加行号)/ -v(显示不匹配)
2222```
@@ -43,7 +43,7 @@ ack官网列出了这工具的5大卖点:
4343
4444grep常用操作
4545
46- ``` bash
46+ ``` shell
4747grep -r ' hello_world' # 简单用法
4848grep ' ^hello_world' . # 简单正则
4949ls -l | grep .py # 管道用法
@@ -65,7 +65,7 @@ ack-grep -Q 'hello*'
6565
6666对搜索结果进行处理,比如只显示一个文件的一个匹配项,或者xxx
6767
68- ``` bash
68+ ``` shell
6969ack-grep --line=1 # 输出所有文件第二行
7070ack-grep -l ' hello' # 包含的文件名
7171ack-grep -L ' print' # 非包含文件名
@@ -75,7 +75,7 @@ ack-grep -L 'print' # 非包含文件名
7575
7676输出的结果是以什么方式展示呢,这个部分有几个参数可以练习下
7777
78- ``` bash
78+ ``` shell
7979ack-grep hello --pager=' less -R' # 以less形式展示
8080ack-grep hello --noheading # 不在头上显示文件
8181ack-grep hello --nocolor # 不对匹配字符着色
@@ -84,7 +84,7 @@ ack-grep hello --nocolor # 不对匹配字符着色
8484### File finding
8585没错,它可以查找文件,以省去你要不断的结合find和grep的麻烦,虽然在linux的思想是一个工具做好一件事。
8686
87- ``` bash
87+ ``` shell
8888ack-grep -f hello.py # 查找全匹配文件
8989ack-grep -g hello.py$ # 查找正则匹配文件
9090ack-grep -g hello --sort-files # 查找然后排序
@@ -94,7 +94,7 @@ ack-grep -g hello --sort-files # 查找然后排序
9494
9595文件过滤,个人觉得这是一个很不错的功能。如果你曾经在搜索项目源码是不小心命中日志中的某个关键字的话,你会觉得这个有用。
9696
97- ``` bash
97+ ``` shell
9898ack-grep --python hello # 查找所有python文件
9999ack-grep -G hello.py$ hello # 查找匹配正则的文件
100100```
0 commit comments