命令行的全文搜索工具--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

相關文章
相關標籤/搜索