Find命令
参考知识点:
https://blog.csdn.net/lilygg/article/details/84076757
https://blog.csdn.net/qq_40993864/article/details/104640109
语法
find+[路径]+[参数]
-name #文件名
-not #非,取反
-user #文件所有人
-group #文件所有组
-a #并且关系
-o #或者关系
常用参数的使用
name-按照文件名查找
[root@localhost ~]# find /etc/ -name ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-ens33
user-按文件的所有人查找
[root@localhost ~]# find /home -user root
/home
group-按文件的所有组查找
[root@localhost ~]# find /mnt -group westos
/mnt/file2
/mnt/file3
a表示并且
and:逻辑与,在命令中用“-a”表示,是系统缺省的选项,表示只有当所给的条件都满足时,寻找条件才算满足
默认不加任何参数也是表示并且
#基本使用链接多个筛选条件
[root@localhost ~]# find /mnt -user root -a -group westos
/mnt/file2
#/home目录及子目录下查找所有以.txt和.pdf结尾的文件.
find /home \( -name "*.txt" -o -name "*.pdf" \)
或
find /home -name "*.txt" -o -name "*.pdf"
#匹配文件路径或者文件,路径名符合local的文件
find /usr/ -path "*local*"
#匹配tmp或hhh*的所有文件
#or:逻辑或,在命令中用“-o”表示。该运算符表示只要所给的条件中有一个满足 时,寻找条件就算满足。例如:
find –name ’tmp’ –o –name ’hhh*’
o表示或者
or:逻辑或,在命令中用“-o”表示。该运算符表示只要所给的条件中有一个满足 时,寻找条件就算满足。
find –name ’tmp’ –o –name ’hhh*’
[root@localhost ~]# find /mnt -user root -o -group westos
/mnt
/mnt/file2
/mnt/file3
/mnt/file4
/mnt/file5
not-表示非,即反向选择
否定not:逻辑非,在命令中用“!”表示。该运算符表示查找不满足所给条件的文件 。例如:
#找出/home下不是以.txt结尾的文件
find /home ! -name "*.txt"
[root@localhost ~]# find /mnt -not -user student
/mnt
/mnt/file2
/mnt/file4
/mnt/file5
特殊参数
maxdepth和mindepth
按文件所在的深度(层次)查找
-maxdepth #最大深度
-mindepth #最小深度
举例说明
##-maxdepth表示最大深度,即最多层次
[root@localhost ~]# find /etc/ -maxdepth 1 -name passwd
/etc/passwd
[root@localhost ~]# find /etc/ -maxdepth 2 -name passwd
/etc/passwd
/etc/pam.d/passwd
[root@localhost ~]#
##-mindepth表示最小深度,即最少层次
[root@localhost ~]# find /etc/ -mindepth 2 -name passwd
/etc/pam.d/passwd
[root@localhost ~]# find /etc/ -mindepth 1 -name passwd
/etc/passwd
/etc/pam.d/passwd
size 表示文件大小
size的说明:
#等于大于小于的表示
-size 20K