设备中的文件查找
1.find命令是用来查询指定文件,用法如下
find
-name ##查找条件为文件名称
-user ##查找某个用户的文件
-group ##查找某个组的文件
-type ##查找某个类型的文件
-perm ##按照拥有某种权限的文件
-exec ##对查找出来的内容进行相应处理
-maxdepth ##设定查找最大深度
-mindepth ##设定查找最浅深度
-o ##条件或
-a ##条件且
-not ##条件否
2.-name 通过文件名来查找
[root@yxy Desktop]# find /etc/ -name passwd
/etc/pam.d/passwd
/etc/passwd
[root@yxy Desktop]# find /etc/ -name *.conf
/etc/dnf/dnf.conf
/etc/dnf/plugins/copr.conf
/etc/dnf/plugins/debuginfo-install.conf
3.-group表示文件的所有组,-user表示文件所有人
<1>搭建实验环境
<2>实验过程
[root@yxy ~]# find /mnt/ -user yyy
/mnt/westosfile3
/mnt/westosfile5
[root@yxy ~]# find /mnt/ -group lll
/mnt/westosfile2
/mnt/westosfile5
[root@yxy ~]# find /mnt/ -user root -a -group yyy
/mnt/westosfile1
-a表示且
[root@yxy ~]# find /mnt/ -user root -o -group lll
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile5
/mnt/westosfile6
/mnt/westosdir
/mnt/westosdir/westostest1
/mnt/westosdir/westostest2
/mnt/westosdir/westostest3
/mnt/westosdir/westostest4
/mnt/westosdir/westostest5
-o表示或
[root@yxy ~]# find /mnt/ -not -user root
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
-not表示非,也就是反向选择
4.文件深度查询
-mindepth ##最小深度
[root@yxy ~]# find /mnt/ -mindepth 1 -name westos*
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosfile6
/mnt/westosdir
/mnt/westosdir/westostest1
/mnt/westosdir/westostest2
/mnt/westosdir/westostest3
/mnt/westosdir/westostest4
/mnt/westosdir/westostest5
[root@yxy ~]# find /mnt/ -mindepth 2 -name westos*
/mnt/westosdir/westostest1
/mnt/westosdir/westostest2
/mnt/westosdir/westostest3
/mnt/westosdir/westostest4
/mnt/westosdir/westostest5
-maxdepth ##最大深度
[root@yxy ~]# find /mnt/ -maxdepth 1 -name westos*
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosfile6
/mnt/westosdir
[root@yxy ~]# find /mnt/ -maxdepth 2 -name westos*
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosfile6
/mnt/westosdir
/mnt/westosdir/westostest1
/mnt/westosdir/westostest2
/mnt/westosdir/westostest3
/mnt/westosdir/westostest4
/mnt/westosdir/westostest5
5.文件权限查询
1.建立实验环境
[root@yxy mnt]# chmod 700 westosfile1
[root@yxy mnt]# chmod 060 westosfile2
[root@yxy mnt]# chmod 002 westosfile3
[root@yxy mnt]# chmod 755 westosfile4
[root@yxy mnt]# chmod 111 /mnt/westosfile6
[root@yxy ~]# find /mnt/ -perm 111
/mnt/westosfile6
[root@yxy ~]# find /mnt/ -perm -111 #文件权限u位有1,g位有1,o位有1
/mnt/
/mnt/westosfile4
/mnt/westosfile6
/mnt/westosdir
[root@yxy ~]# find /mnt/ -perm /111 #文件权限u或g或o位有1
/mnt/
/mnt/westosfile1
/mnt/westosfile4
/mnt/westosfile6
/mnt/westosdir
[root@yxy ~]# find /mnt/ -perm /111 -type f -exec chmod ugo-x {} \;
# f 表示类型位文件
#{} 表示find命令查找结果
# \ 是为了转译“ ; ”