系统相关
首页 > 系统相关> > 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

 

标签:02,csv,命令,centos79,linux,test,txt,root,find
来源: https://www.cnblogs.com/liujiaxin2018/p/14974654.html