访问次数
我的另一个总结性博客: todototry 大米粒

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

posted @   fandyst  阅读(2013)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示