linux中find命令排除指定目录进行查找

发布时间 2023-09-22 09:34:32作者: 小鲨鱼2018

 

001、

[root@pc1 dir001]# ls
test01  test02  ww.txt  xx.map
[root@pc1 dir001]# find -not -path "./test01/*" -name "*.txt"
./test02/mm.txt
./test02/dirxx/diryy/tt.txt
./ww.txt
[root@pc1 dir001]# find ! -path "./test01/*" -name "*.txt"
./test02/mm.txt
./test02/dirxx/diryy/tt.txt
./ww.txt
[root@pc1 dir001]# find -not -path "/home/dir001/test01/*" -name "*.txt"
./test01/kk.txt
./test02/mm.txt
./test02/dirxx/diryy/tt.txt
./ww.txt

 

002、同时限定多个目录

[root@pc1 dir001]# ls
test01  test02  ww.txt  xx.map
[root@pc1 dir001]# find -not -path "./test01/*" -not -path "./test02/*" -name "*.txt"
./ww.txt
[root@pc1 dir001]# find \( -not -path "./test01/*" -a -not -path "./test02/*" \) -name "*.txt"
./ww.txt
[root@pc1 dir001]# find -not \( -path "./test01/*" -o -path "./test02/*" \) -name "*.txt"
./ww.txt