您的位置:首页 > 运维架构 > Linux

Linux下find一次查找多个指定类型文件,指定文件或者排除某类文件,在 GREP 中匹配多个关键

2016-06-20 00:00 926 查看
Linux下find一次查找多个指定文件或者排除某类文件,在 GREP 中匹配多个关键字的方法

(1)Linux下find一次查找多个指定文件:
查找a.html和b.html

[code=language-bash]find . -name "a.html"  -name "b.html"

find . -regex '.*\.txt\|.*\.doc\|.*\.mp3'

[code=language-bash]find . -regex '.*\.txt\|.*\.doc\|.*\.mp3'
./a.txt
./a.doc
./a.mp3

(2)排除某些文件类型:
排除目录下所有以html结尾的文件:

[code=language-bash]find . -type f ! -name "*.html"
./ge.bak.02.09
./ge.html.changed.by.jack
./a.txt
./a.doc
./a.mp3

(3)排除多种文件类型的示例:

[code=language-bash]find . -type f ! -name "*.html" -type  f ! -name "*.php" -type  f ! -name "*.svn-base"  -type  f ! -name "*.js"  -type  f ! -name "*.gif"  -type  f ! -name "*.png"  -type  f ! -name "*.cpp"  -type  f ! -name "*.h"  -type  f ! -name "*.o"  -type  f ! -name "*.jpg"

(4)在 GREP 中匹配多个关键字的方法:
grep查找多个数字的文件:
-r 递归,-E:正则 -l:只显示文件名

[code=language-bash]root@116.255.139.240:~/a# grep -r -E '0341028|100081|10086|10001' *
a.txt:100081
b.txt:10086
c/cc.txt:0341028
c/cc.txt:100081
c/cc.txt:10086
c/cc.txt:10001
c.txt:10001
d.txt:0341028

[code=language-bash]grep -r  -E -l '0341028|100081|10086|10001' *
a.txt
b.txt
c/cc.txt
c.txt
d.txt

多种类型文件示例:

[code=language-bash]find . -name "*.html" -o -name "*.js"|xargs grep -r "BusiTree"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: