1. 程式人生 > 其它 >linux系統中find命令

linux系統中find命令

linux系統中find命令

1、直接查詢檔名

測試檔案如下:

[root@centos79 test]# ls
01.txt  02.csv  02.txt  03.csv  04.txt
[root@centos79 test]# find "02.txt"
02.txt
[root@centos79 test]# find *.csv
02.csv
03.csv

2、find後加查詢的路徑、 使用-name引數指定檔名

[root@centos79 test]# ls
01.txt  02.csv  02.txt  03.csv  04.txt
[root@centos79 test]# find ./ -name "
03.csv"
./03.csv [root@centos79 test]# find ./ -name "*.txt" ./01.txt ./04.txt ./02.txt

指定目錄:

[root@centos79 test]# ls
01.txt  02.csv  02.txt  03.csv  04.txt
[root@centos79 test]# mkdir test01 test02
[root@centos79 test]# cp *.txt *.csv test01
[root@centos79 test]# cp *.txt *.csv test02
[root@centos79 test]# find .
/test01/ -name "*.txt" ./test01/01.txt ./test01/02.txt ./test01/04.txt [root@centos79 test]# ls 01.txt 02.csv 02.txt 03.csv 04.txt test01 test02

3、查詢時,使用-iname引數忽略檔名的大小寫

[root@centos79 test]# ls
01.txt  01.TXT  02.csv  02.txt  03.csv  04.txt
[root@centos79 test]# find ./ -name "01.txt"
./01.txt
[root@centos79 test]# find .
/ -iname "01.txt" ./01.txt ./01.TXT

4、-not引數或者 !反向查詢

[root@centos79 test]# ls
01.txt  02.csv  03.csv  04.txt
[root@centos79 test]# find ./ -name "01.txt"
./01.txt
[root@centos79 test]# find ./ -not -name "01.txt"
./
./04.txt
./03.csv
./02.csv
[root@centos79 test]# find ./ ! -name "01.txt"
./
./04.txt
./03.csv
./02.csv

繼續:

[root@centos79 test]# ls
01.txt  02.csv  03.csv  04.txt
[root@centos79 test]# find ./ -name "*.txt"
./01.txt
./04.txt
[root@centos79 test]# find ./ -not -name "*.txt"
./
./03.csv
./02.csv
[root@centos79 test]# find ./ ! -name "*.txt"
./
./03.csv
./02.csv