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

news/2024/7/5 4:06:06

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

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

转载于:https://www.cnblogs.com/ToDoToTry/p/4444063.html


http://lihuaxi.xjx100.cn/news/272533.html

相关文章

通用权限管理组件使用说明书V3.0 错误校正 感谢自由软件职业者Helper(767870484)...

有时候,真想做个像样的东西出来,但是往往各方面的能力都不够,这么多人,Helper(767870484)仔细认真的阅读了这个帮助手册、并给给于了指正,在这里非常感谢,你的劳动成果已经被通用权限…

51NOD 1773:A国的贸易——题解

http://www.51nod.com/onlineJudge/questionCode.html#!problemId1773 参考1:FWT讲解 https://www.cnblogs.com/RabbitHu/p/9182047.html 参考2:题解 https://www.cnblogs.com/ivorysi/p/9178577.html (令$\oplus$表示异或) 设$dp…

《评人工智能如何走向新阶段》后记(再续18)

由AI科技大本营下载273.人工智能与人脑智能 近年来人工智能取得了巨大进步,受人脑神经元调节机制启发的人工智能新颖算法层出不穷!但人工智能离人脑智能(或称人类智能)还差得很远,而人脑(神经元&#xff0…

2020 Top10 计算机视觉论文总结:论文,代码,解读,还有demo视频!

点击上方“视学算法”,选择加"星标"或“置顶”重磅干货,第一时间送达作者丨louisfb01来源丨AI公园编辑丨极市平台尽管今年世界上发生了这么多事情,我们还是有机会看到很多惊人的研究成果。特别是在人工智能更精确的说是计算机视觉领…

Pygame Rect区域位置(图解)

Rect(rectangle)指的是矩形,或者长方形,在 Pygame 中我们使用 Rect() 方法来创建一个指定位置,大小的矩形区域。函数的语法格式如下: rect pygame.Rect(left,top,width,height) Rect 表示的区域必须位于…

springboot集成普罗米修斯

点击上方“方志朋”,选择“设为星标”回复”666“获取新整理的面试文章Prometheus 是一套开源的系统监控报警框架。它由工作在 SoundCloud 的 员工创建,并在 2015 年正式发布的开源项目。2016 年,Prometheus 正式加入 Cloud Native Computing…

Python中相见恨晚的技巧(记得收藏)

话不多说,直接开干,攒了很久! 1. 交换变量值 这个应该比较简单,但是日常用很容易忽略。 a, b 5, 10 print(a, b) //5, 10 a, b b, a print(a, b) //10, 5 | 2. 将列表中所有元素组合成字符串 这个其实也是一个基本语法…

Redis基础、应用、第三方支持组件总结

这段时间一直在研究学习Redis的相关知识,现在大概做下总结吧首先,Redis的基础方面,不说配置,就单单说下Redis数据类型:Redis 五大数据类型有String 类型,Hash 类型,List 类型,Set 类…