6
6
## 安装
7
7
8
8
``` bash
9
- # ubuntu下要安装ack-grep
9
+ # ubuntu下要安装ack-grep,因为在debian系中,ack这个名字被其他的软件占用了。
10
10
sudo apt-get install ack-grep
11
11
```
12
12
13
+ ## 参数
14
+
15
+ 这些参数在linux上的适用频率是相当高的,尤其是你用vim做为IDE的话
16
+
17
+ ```
18
+ -c(统记)/ -i(忽略大小)/ -h(不显示名称)/
19
+ -l(只显文件名)/ -n(加行号)/ -v(显示不匹配)
20
+ ```
21
+
13
22
## 特点
14
23
15
24
ack官网列出了这工具的5大卖点:
@@ -22,10 +31,71 @@ ack官网列出了这工具的5大卖点:
22
31
23
32
## 实例
24
33
34
+ 在记忆的时候大体上可以分为这几个部分:
35
+
36
+ > Searching 代码搜索
37
+ > Search output 搜索结果处理
38
+ > File presentation 文件展示
39
+ > File finding 文件查找
40
+ > File inclusion/exclusion 文件过滤
41
+
42
+ grep常用操作
43
+
44
+ ``` bash
45
+ grep -r ' hello_world' # 简单用法
46
+ grep ' ^hello_world' . # 简单正则
47
+ ls -l | grep .py # 管道用法
25
48
```
26
- ack
49
+
50
+ ### Searching
51
+
52
+ 简单的文本搜索,默认是递归的。
53
+
54
+ ```
55
+ ack-grep hello
56
+ ack-grep -i hello
57
+ ack-grep -v hello
58
+ ack-grep -w hello
59
+ ack-grep -Q 'hello*'
60
+ ```
61
+
62
+ ### Search File
63
+
64
+ 对搜索结果进行处理,比如只显示一个文件的一个匹配项,或者xxx
65
+
66
+ ``` bash
67
+ ack-grep --line=1 # 输出所有文件第二行
68
+ ack-grep -l ' hello' # 包含的文件名
69
+ ack-grep -L ' print' # 非包含文件名
70
+ ```
71
+
72
+ ### File presentation
73
+
74
+ 输出的结果是以什么方式展示呢,这个部分有几个参数可以练习下
75
+
76
+ ``` bash
77
+ ack-grep hello --pager=' less -R' # 以less形式展示
78
+ ack-grep hello --noheading # 不在头上显示文件
79
+ ack-grep hello --nocolor # 不对匹配字符着色
27
80
```
28
81
82
+ ### File finding
83
+ 没错,它可以查找文件,以省去你要不断的结合find和grep的麻烦,虽然在linux的思想是一个工具做好一件事。
84
+
85
+ ``` bash
86
+ ack-grep -f hello.py # 查找全匹配文件
87
+ ack-grep -g hello.py$ # 查找正则匹配文件
88
+ ack-grep -g hello --sort-files # 查找然后排序
89
+ ```
90
+
91
+ ### File Inclusion/Exclusion
92
+
93
+ 文件过滤,个人觉得这是一个很不错的功能。如果你曾经在搜索项目源码是不小心命中日志中的某个关键字的话,你会觉得这个有用。
94
+
95
+ ``` bash
96
+ ack-grep --python hello # 查找所有python文件
97
+ ack-grep -G hello.py$ hello # 查找匹配正则的文件
98
+ ```
29
99
30
100
## 参考资料
31
101
0 commit comments