linux 如何在文本文件中用Terminal的grep命令查找一个词

来源:互联网 发布:怎样申请做淘宝模特 编辑:程序博客网 时间:2024/06/03 23:00

问题
当ubuntu中,想查找一个词语在哪个文件里出现过, 用什么命令呢?

解决方法
1 在当前路径下全文件查找任何文件中包含的s:grep -r "s" *

2 在文件a中查找s并且显示行号:grep -nr "s" a

3 实例

aston@ubuntu:~/Downloads$ grep -r "s" * //全路径搜索,不显示行号Binary file .v.c.swp matchesBinary file sogoupinyin_2.1.0.0086_i386(1).deb matchesa:sa:asa:sa:pasfasBinary file sogoupinyin_2.1.0.0086_i386.deb matchesBinary file sogoupinyin_2.1.0.0086_amd64.deb matchesBinary file .a.c.swp matchesaston@ubuntu:~/Downloads$ grep -nr "s" * //全路径搜索,并且显示行号Binary file .v.c.swp matchesBinary file sogoupinyin_2.1.0.0086_i386(1).deb matchesa:1:sa:7:asa:12:sa:13:pasfasBinary file sogoupinyin_2.1.0.0086_i386.deb matchesBinary file sogoupinyin_2.1.0.0086_amd64.deb matchesBinary file .a.c.swp matchesaston@ubuntu:~/Downloads$ grep -r "s" a //在文件a中搜索s,不显示行号sasspasfas
阅读全文
0 0
原创粉丝点击