命令行的全文搜索工具--ack

想必大家在命令行环境下工作时候,一定有想要查找当前目录下的源代码文件中的某些字符的需求,这时候如果使用传统方案,你可能需要输入一长串的命令,比如这样:

1. grep -R 'string' dir/    或者 grep -r -e string directory

2. grep -rnw 'directory' -e "pattern"

3. grep --include=\*.{c,h} -rnw 'directory' -e "pattern"

4. grep --exclude=*.o -rnw 'directory' -e "pattern"

5. grep --exclude-dir={dir1,dir2,*.dst} -rnw 'directory' -e "pattern"

6. find dir/ -type f -exec grep -H 'string' {} +

或者更复杂的情况你可能需要管道与awk组合。

 

这里推荐一个命令行下的全文搜索工具:ack,非常方便地查找搜索,还支持高亮和文件行数定位。示例图如下: 

安装方法:

Macports
  Port "perl/p5-app-ack"
Homebrew on Mac
  Formula "ack"
FreeBSD port
  Port "textproc/p5-ack"
OpenBSD port
  Package "p5-ack"
Debian
  Package "ack-grep"
  (To rename the "ack-grep" program to its proper name "ack", see the section below on renaming ack-grep)
Ubuntu
  Package "ack-grep"
Fedora
  Package "ack"
Gentoo
  Package "sys-apps/ack"
Sabayon
  Package "sys-apps/ack"
Arch
  Package "community/ack"
Chocolatey for Windows
  http://chocolatey.org/packages/ack
NixOS
  Package "perl-ack"

 

 

参考链接:

0. ack 官网: http://beyondgrep.com/

1. find a text in all files in a dir :  http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux

2. how to grep a string in a dir:  http://stackoverflow.com/questions/15622328/how-to-grep-a-string-in-a-directory-and-all-its-subdirectories-files-in-linux

3.  linux 利器: http://coolshell.cn/articles/7829.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值