10
10
< meta name ="keywords " content ="Linux,Command,命令大全,Linux命令手册,ack,比grep好用的文本搜索工具 ">
11
11
< title > ack 命令,Linux ack 命令详解:比grep好用的文本搜索工具 - Linux 命令搜索引擎</ title >
12
12
< link rel ="shortcut icon " href ="../img/favicon.ico ">
13
- < link rel ="stylesheet " type ="text/css " href ="../css/index.css?v=1532764391986 ">
13
+ < link rel ="stylesheet " type ="text/css " href ="../css/index.css?v=1538882023295 ">
14
14
</ head >
15
15
< body >
16
16
< a href ="https://github.com/jaywcjlove/linux-command " target ="_blank " class ="github-corner "> < svg viewBox ="0 0 250 250 "> <!-- kenny wang <wowohoo@qq.com> https://github.com/jaywcjlove --> < title > logo</ title > < desc > Linux Command Logo. https://github.com/jaywcjlove</ desc > < path d ="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z "> </ path > < path d ="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2 " fill ="currentColor " style ="transform-origin: 130px 106px; " class ="octo-arm "> </ path > < path d ="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z " fill ="currentColor " class ="octo-body "> </ path > </ svg > </ a >
41
41
</ span >
42
42
43
43
< h1 id ="ack "> ack</ h1 > < p > 比grep好用的文本搜索工具</ p >
44
- < h2 id ="安装 "> 安装</ h2 > < pre > < code class ="lang-bash "> < span class ="hljs-comment "> # ubuntu下要安装ack-grep,因为在debian系中,ack这个名字被其他的软件占用了。</ span >
45
- sudo apt-get install ack-grep
46
- < span class ="hljs-comment "> # alpine Linux-apk软件包管理器 安装 ack</ span >
47
- apk install ack
48
- </ code > </ pre >
44
+ < h2 id ="安装 "> 安装</ h2 > < pre > < code class ="language-bash "> < span class ="token macro property "> # ubuntu下要安装ack-grep,因为在debian系中,ack这个名字被其他的软件占用了。</ span >
45
+ sudo apt< span class ="token operator "> -</ span > get install ack< span class ="token operator "> -</ span > grep
46
+ < span class ="token macro property "> # alpine Linux-apk软件包管理器 安装 ack</ span >
47
+ apk install ack</ code > </ pre >
49
48
< h2 id ="参数 "> 参数</ h2 > < p > 这些参数在linux上的适用频率是相当高的,尤其是你用vim做为IDE的话</ p >
50
- < pre > < code > -c(统记)/ -i(忽略大小)/ -h(不显示名称)/
51
- < span class ="hljs-_ "> -l</ span > (只显文件名)/ -n(加行号)/ -v(显示不匹配)
52
- </ code > </ pre > < h2 id ="特点 "> 特点</ h2 > < p > ack官网列出了这工具的5大卖点:</ p >
49
+ < pre > < code > -c< span class ="token punctuation "> (</ span > 统记< span class ="token punctuation "> )</ span > / -i< span class ="token punctuation "> (</ span > 忽略大小< span class ="token punctuation "> )</ span > / -h< span class ="token punctuation "> (</ span > 不显示名称< span class ="token punctuation "> )</ span > /
50
+ -l< span class ="token punctuation "> (</ span > 只显文件名< span class ="token punctuation "> )</ span > / -n< span class ="token punctuation "> (</ span > 加行号< span class ="token punctuation "> )</ span > / -v< span class ="token punctuation "> (</ span > 显示不匹配< span class ="token punctuation "> )</ span > </ code > </ pre > < h2 id ="特点 "> 特点</ h2 > < p > ack官网列出了这工具的5大卖点:</ p >
53
51
< ol >
54
52
< li > 速度非常快,因为它只搜索有意义的东西。</ li >
55
53
< li > 更友好的搜索,忽略那些不是你源码的东西。</ li >
@@ -62,35 +60,29 @@ <h2 id="实例">实例</h2><p>在记忆的时候大体上可以分为这几个
62
60
< p > Searching 代码搜索< br > Search output 搜索结果处理< br > File presentation 文件展示< br > File finding 文件查找< br > File inclusion/exclusion 文件过滤 </ p >
63
61
</ blockquote >
64
62
< p > grep常用操作</ p >
65
- < pre > < code class ="lang-bash "> grep -r < span class ="hljs-string "> 'hello_world'</ span > < span class ="hljs-comment "> # 简单用法</ span >
66
- grep < span class ="hljs-string "> '^hello_world'</ span > . < span class ="hljs-comment "> # 简单正则</ span >
67
- ls < span class ="hljs-_ "> -l</ span > | grep .py < span class ="hljs-comment "> # 管道用法</ span >
68
- </ code > </ pre >
63
+ < pre > < code class ="language-bash "> grep < span class ="token operator "> -</ span > r < span class ="token string "> 'hello_world'</ span > # 简单用法
64
+ grep < span class ="token string "> '^hello_world'</ span > < span class ="token punctuation "> .</ span > # 简单正则
65
+ ls < span class ="token operator "> -</ span > l < span class ="token operator "> |</ span > grep < span class ="token punctuation "> .</ span > py # 管道用法</ code > </ pre >
69
66
< h3 id ="searching "> Searching</ h3 > < p > 简单的文本搜索,默认是递归的。</ p >
70
67
< pre > < code > ack-grep hello
71
68
ack-grep -i hello
72
69
ack-grep -v hello
73
70
ack-grep -w hello
74
- ack-grep -Q < span class ="hljs-string "> 'hello*'</ span >
75
- </ code > </ pre > < h3 id ="search-file "> Search File</ h3 > < p > 对搜索结果进行处理,比如只显示一个文件的一个匹配项,或者xxx</ p >
76
- < pre > < code class ="lang-bash "> ack-grep --line=1 < span class ="hljs-comment "> # 输出所有文件第二行</ span >
77
- ack-grep < span class ="hljs-_ "> -l</ span > < span class ="hljs-string "> 'hello'</ span > < span class ="hljs-comment "> # 包含的文件名</ span >
78
- ack-grep -L < span class ="hljs-string "> 'print'</ span > < span class ="hljs-comment "> # 非包含文件名</ span >
79
- </ code > </ pre >
71
+ ack-grep -Q < span class ="token string "> 'hello*'</ span > </ code > </ pre > < h3 id ="search-file "> Search File</ h3 > < p > 对搜索结果进行处理,比如只显示一个文件的一个匹配项,或者xxx</ p >
72
+ < pre > < code class ="language-bash "> ack< span class ="token operator "> -</ span > grep < span class ="token operator "> --</ span > line< span class ="token operator "> =</ span > < span class ="token number "> 1</ span > # 输出所有文件第二行
73
+ ack< span class ="token operator "> -</ span > grep < span class ="token operator "> -</ span > l < span class ="token string "> 'hello'</ span > # 包含的文件名
74
+ ack< span class ="token operator "> -</ span > grep < span class ="token operator "> -</ span > L < span class ="token string "> 'print'</ span > # 非包含文件名</ code > </ pre >
80
75
< h3 id ="file-presentation "> File presentation</ h3 > < p > 输出的结果是以什么方式展示呢,这个部分有几个参数可以练习下</ p >
81
- < pre > < code class ="lang-bash "> ack-grep hello --pager=< span class ="hljs-string "> 'less -R'</ span > < span class ="hljs-comment "> # 以less形式展示</ span >
82
- ack-grep hello --noheading < span class ="hljs-comment "> # 不在头上显示文件</ span >
83
- ack-grep hello --nocolor < span class ="hljs-comment "> # 不对匹配字符着色</ span >
84
- </ code > </ pre >
76
+ < pre > < code class ="language-bash "> ack< span class ="token operator "> -</ span > grep hello < span class ="token operator "> --</ span > pager< span class ="token operator "> =</ span > < span class ="token string "> 'less -R'</ span > # 以less形式展示
77
+ ack< span class ="token operator "> -</ span > grep hello < span class ="token operator "> --</ span > noheading # 不在头上显示文件
78
+ ack< span class ="token operator "> -</ span > grep hello < span class ="token operator "> --</ span > nocolor # 不对匹配字符着色</ code > </ pre >
85
79
< h3 id ="file-finding "> File finding</ h3 > < p > 没错,它可以查找文件,以省去你要不断的结合find和grep的麻烦,虽然在linux的思想是一个工具做好一件事。</ p >
86
- < pre > < code class ="lang-bash "> ack-grep < span class ="hljs-_ "> -f</ span > hello.py < span class ="hljs-comment "> # 查找全匹配文件</ span >
87
- ack-grep -g hello.py$ < span class ="hljs-comment "> # 查找正则匹配文件</ span >
88
- ack-grep -g hello --sort-files < span class ="hljs-comment "> # 查找然后排序</ span >
89
- </ code > </ pre >
80
+ < pre > < code class ="language-bash "> ack< span class ="token operator "> -</ span > grep < span class ="token operator "> -</ span > f hello< span class ="token punctuation "> .</ span > py # 查找全匹配文件
81
+ ack< span class ="token operator "> -</ span > grep < span class ="token operator "> -</ span > g hello< span class ="token punctuation "> .</ span > py$ # 查找正则匹配文件
82
+ ack< span class ="token operator "> -</ span > grep < span class ="token operator "> -</ span > g hello < span class ="token operator "> --</ span > sort< span class ="token operator "> -</ span > files # 查找然后排序</ code > </ pre >
90
83
< h3 id ="file-inclusion-exclusion "> File Inclusion/Exclusion</ h3 > < p > 文件过滤,个人觉得这是一个很不错的功能。如果你曾经在搜索项目源码是不小心命中日志中的某个关键字的话,你会觉得这个有用。</ p >
91
- < pre > < code class ="lang-bash "> ack-grep --python hello < span class ="hljs-comment "> # 查找所有python文件</ span >
92
- ack-grep -G hello.py$ hello < span class ="hljs-comment "> # 查找匹配正则的文件</ span >
93
- </ code > </ pre >
84
+ < pre > < code class ="language-bash "> ack< span class ="token operator "> -</ span > grep < span class ="token operator "> --</ span > python hello # 查找所有python文件
85
+ ack< span class ="token operator "> -</ span > grep < span class ="token operator "> -</ span > G hello< span class ="token punctuation "> .</ span > py$ hello # 查找匹配正则的文件</ code > </ pre >
94
86
< h2 id ="参考资料 "> 参考资料</ h2 > < ul >
95
87
< li > < a href ="https://beyondgrep.com/ "> ack官网</ a > </ li >
96
88
</ ul >
@@ -101,7 +93,7 @@ <h2 id="参考资料">参考资料</h2><ul>
101
93
收藏本站请使用Ctrl+D或者Command+d
102
94
< br />
103
95
< a target ="_blank " href ="https://github.com/jaywcjlove/linux-command/new/master/command "> 添加命令</ a > |
104
- < a href ="hot.html "> 命令列表</ a > |
96
+ < a href ="../ hot.html "> 命令列表</ a > |
105
97
< a href ="https://github.com/jaywcjlove/oscnews "> Chrome 插件</ a >
106
98
< br > 共搜集到
107
99
< span id ="commands_info ">
@@ -110,7 +102,7 @@ <h2 id="参考资料">参考资料</h2><ul>
110
102
</ div >
111
103
< script >
112
104
var _hmt = _hmt || [ ] ; ( function ( ) { var hm = document . createElement ( "script" ) ; hm . src = "https://hm.baidu.com/hm.js?a542c0213a9aa8ae29fccdc8a18b91ef" ; var s = document . getElementsByTagName ( "script" ) [ 0 ] ; s . parentNode . insertBefore ( hm , s ) ; } ) ( ) ; </ script >
113
- < script type ="text/javascript " src ="../js/dt.js?v=1532764391987 "> </ script >
114
- < script type ="text/javascript " src ="../js/index.js?v=1532764391987 "> </ script >
105
+ < script type ="text/javascript " src ="../js/dt.js?v=1538882023296 "> </ script >
106
+ < script type ="text/javascript " src ="../js/index.js?v=1538882023296 "> </ script >
115
107
</ body >
116
108
</ html >
0 commit comments