可见:Linux的文件、目录、磁盘和文件系统——1.5 与文件和目录相关的命令
1. 查找所有".h"文件
find /PATH -name "*.h"
2. 查找所有".h"文件中的含有"helloworld"字符串的文件
find /PATH -name "*.h" -exec grep -in "helloworld" {} \;
find /PATH -name "*.h" | xargs grep -in "helloworld"
3. 查找所有".h"和".c"文件中的含有"helloworld"字符串的文件
find /PATH /( -name "*.h" -or -name "*.c" /) -exec grep -in "helloworld" {} \;
4. 查找非备份文件中的含有"helloworld"字符串的文件
find /PATH /( -not -name "*~" /) -exec grep -in "helloworld" {} \;
注:/PATH
为查找路径,默认为当前路径。带-exec参数时必须以\;结尾,否则会提示“find: 遗漏“-exec”的参数”。
使用find和xargs:
find pathname -options [-print -exec -ok]
-name
:按照文件名查找-perm
:按照权限查找文件-prune
-user
和-nouser
-group
和-nogroup
按照时间
按照类型查找
按照大小
查找位于本文件系统里面的文件
2. xargs与-exec功能类似
find ~ -type f | xargs ls -l
svn过滤svn文件夹
grep多个过滤条件
1、或操作
grep -E '123|abc' filename // 找出文件(filename)中包含123或者包含abc的行
egrep '123|abc' filename // 用egrep同样可以实现
awk '/123|abc/' filename // awk 的实现方式
2、与操作
grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。
3、其他操作
grep -i pattern files :不区分大小写地搜索。默认情况区分大小写,
grep -l pattern files :只列出匹配的文件名,
grep -L pattern files :列出不匹配的文件名,
grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’),
grep -C number pattern files :匹配的上下文分别显示[number]行,
find过滤svn文件夹
find -type f ! -path '*/.svn/*'