Linux的存储原理(2) ---设备中文件查找(find指令的用法)、通过名称、所有人和所有组、深度、权限大小查找文件

设备中的文件查找

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命令查找结果
# \ 是为了转译“ ; ”

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值