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

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

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

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

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

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' {} +orm

或者更复杂的状况你可能须要管道与awk组合。htm

 

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

安装方法:string

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

相关文章
相关标签/搜索