find命令是用来查询指定文件,用法如下
1.-name 通过文件名来查找
[root@localhost ~]# find /etc/ -name passwd /etc/passwd /etc/pam.d/passwd [root@localhost mnt]# find /etc/ -name *.conf
2.-group表示文件的所有组,-user表示文件所有人
搭建实验环境
实验开始
[root@localhost ~]# find /mnt -user student /mnt/file1 /mnt/file3
[root@localhost ~]# find /mnt -group westos /mnt/file2 /mnt/file3
[root@localhost ~]# find /mnt -user root -group westos /mnt/file2 -a表示并且
[root@localhost ~]# find /mnt -user root -a -group westos /mnt/file2 -o表示或者
[root@localhost ~]# find /mnt -not -user student -not表示非;即反向选择
3.文件深度查询
-maxdepth ##最大深度 -mindepth ##最小深度 [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 ~]# find /etc/ -mindepth 1 -maxdepth 2 -name *.conf
4.文件大小查询
建立实验环境
5.指定文件类型查询
-type ##根据指定类型查找(-,d,l,s,f,b)
6.指定文件创建时间查询
find -cmin 10 ##查找10min结点上修改过的文件 find -cmin -10 ##查找10min以内修改过的文件 find -cmin +10 ##修改超过10min的文件 find -ctime +|-|10 ##不指定默认为查找时间为:天
7.权限查询法
find -perm 644 ##查找指定权限(004)的文件 find -perm -644 ## "-"表示“与”,ug位无要求且o为有r权限 find -perm /644 ## '/'表示'或',只要o位有r权限即可
搭建实验环境
实验
-exec commd {} \ {}表示find的输出 -exec 后加想要执行的动作 必须是空格后加\;\表示对分号进行转义