find -name "*" |xargs grep "xxx" ubuntu搜索
2015-11-12 16:28
411 查看
在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选项一定要加,要不然会在替换的时候会提示文件打不开,
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选项一定要加,要不然会在替换的时候会提示文件打不开,
相关文章推荐
- NYOJ 528 找球号(三) 【位运算 ^ 】
- 时间复杂度及其计算
- 时间复杂度及其计算
- Java8教程
- HDU3336(KMP + dp)
- hihoCoder #1054 dfs
- 其他程序员的博客(持续更新)
- 配置mybatis和ibatis控制台打印sql语句
- 计算机视觉领域的一些牛人博客+超有实力的研究机构等的网站链接
- iOS_创建文件夹与删除文件夹
- Largest Number
- [DM8168] EVM816x DDR2/3 PRCM Init is Done(DMM_LISA_MAP 修改 EMIF 映射)
- Verilog编程testbench的注意事项
- 实况:《编译原理》期末考试一天复习
- 【Android】JNICALL could not be resolved
- Bilateral Filtering(双边滤波) for SSAO
- Android AsyncTask完全解析(源码角度)
- C++异常以及错误处理
- 异步通信、Handler
- android ProgressBar被拉伸或压缩变形,显示不全