find -name "*" |xargs grep "xxx" ubuntu搜索

find -name "*.xml"|xargs grep -nrws "config_systemUIServiceComponents"

解释:*.xml  只查找.xml文件,n是显示行数 r是忽悠大小写,

在ubuntu中搜索文件一直是用的: find -name "*" |xargs grep “xxx",在用了一阵后感觉这命令还是太好,显示的搜索信息太多了,不匹配的搜索结果也显示在控件台中,百度了一下,可以用以下两个参数:

xxxx@ubuntu:~/project/MSM8916_R113502NEW/LINUX/android/packages$ find -name "*" |xargs grep -s "custom_content_page"


./apps/Launcher3/res/layout/custom_content_page_indicator_marker.xml:        android:src="@drawable/custom_content_page"
./apps/Launcher3/res/layout/custom_content_page_indicator_marker.xml:        android:src="@drawable/custom_content_page"


xxxx@ubuntu:~/project/MSM8916_R113502NEW/LINUX/android/packages$ find -name "*" |xargs grep -l "custom_content_page"
./apps/Launcher3/res/layout/custom_content_page_indicator_marker.xml

参数-s 与的-l的区别是 -s 会显示要搜索内容,而-l只会显示匹配搜索的文件名:

grep [options]

3.主要参数

[options]主要参数:

-c:只输出匹配行的计数。

-I:不区分大 小写(只适用于单字符)。

-h:查询多文件时不显示文件名。

-l:查询多文件时只输出包含匹配字符的文件名。

-n:显示匹配行及 行号。

-s:不显示不存在或无匹配文本的错误信息。

-v:显示不包含匹配文本的所有行。

如果想查找当前目录(/home/student)下的tmp.txt文件,但是想要避开sep目录:

 find /home/student -path /home/student/sep -prune -o -name "tmp.txt" -print

 sep后面不能加/ 即/home/student/sep/是错误的 如果当前目录为/home/student 也可以这样

 find . -path ./sep -prune -o -name "tmp.txt" -print

总结:-path 只是匹配find出来的路径,可以通过使用匹配符号* [] ?等 例如:

 [student@bioeng ~]$ find . -name file

./file

./dir/file

./dir/dir555/file

./dir/dir2/file

./dir/dir1/file

[student@bioeng ~]$

 [student@bioeng ~]$ find . -path "*dir[12]" -prune -o -name file -print

./file

./dir/file

./dir/dir555/file

 [student@bioeng ~]$ [student@bioeng ~]$ find . -path "*dir*" -prune -o -name file -print

./file

 [student@bioeng ~]$

如:搜索字符串“SystemUI”并排除out目录:

find . -path ./out -prune -o -name "*.java"|xargs grep -sw "SystemUI"   备注:w选项是精确查找

多关键字搜索:

find -name "*"|xargs grep  -e  'sim|Sim'

查找到替换字符串:

find . -path ./out -prune -o -name "*.java" -print0 | xargs -0 perl -pi -e 's/xxxx/xxxxtihuan/g'  //替换将xxxx字符串搜索出来然后替换成:xxxxtihuan

其中find 命令的-print0选项一定要加,要不然会在替换的时候会提示文件打不开,

猜你喜欢

转载自blog.csdn.net/nei504293736/article/details/49800861
今日推荐