• 关于find的-perm


    关于find的-perm

    参考关于find命令-perm 的用法

    总结

    有三种用法

    • find -perm -mode
    • find -perm mode
    • find -perm /mode(find -perm +mode已经废弃)

    第一种

    find -perm -mode

    -mode表示完全满足mode权限。

    搜索的文件权限可以比mode高

    比如mode位644,那么可以搜索到644的,744的,666的,777也行,比644高就行

    比如,我要/etc目录下权限至少是755的普通文件,

    会发现,755的也满足要求

    [root@centos7 ~]# find /etc/ -perm -011  -type f -print0 | xargs -0 ls -ldh
    -rwxr-xr-x. 1 root root 1.3K Oct 31  2018 /etc/auto.net
    -rwxr-xr-x. 1 root root  687 Oct 31  2018 /etc/auto.smb
    ...
    

    查找/etc⽬录下⾄少有⼀类⽤户没有执⾏权限的⽂件

    先查找所有用户都有执行权限的,再取反

    [root@centos7 tmp]# find /etc/ ( -not -perm -111 )  -type f -print0 | xargs -0 ls -ldh | more
    -rw-r--r--. 1 root root      850 Nov 14  2018 /etc/abrt/abrt-action-save-package-data.conf
    -rw-r--r--. 1 root root     2.1K Nov 14  2018 /etc/abrt/abrt.conf
    

    查找/tmp⽬录下,所有⽤户都有执⾏权限,且其它⽤户有写权限的⽂件

    [root@centos7 tmp]# find /tmp   -perm -113  -type f -print0 | xargs -0 ls -ldh
    -rwx--x-wx 1 root root 0 Aug  3 11:18 /tmp/111.txt
    

    第二种

    find -perm mode

    这样就表示完全匹配了

    我要755的,就给我755,要644的就给我644

    比如:我只要/etc/目录下面权限为755的普通文件

    会发现,所有搜到的文件权限都是755

    [root@centos7 ~]# find /etc/ -perm 755  -type f -print0 | xargs -0 ls -ldh
    -rwxr-xr-x. 1 root root 1.3K Oct 31  2018 /etc/auto.net
    -rwxr-xr-x. 1 root root  687 Oct 31  2018 /etc/auto.smb
    ...
    

    第三种

    find -perm /mode

    /mode表示部分满足即可

    我要755的,那么111的也行,100的也行,但022的不行,因为022(-----w--w-)两个位置不符合要求,不是我要的

    例如:查找/tmp目录下面有执行权限的文件,不管什么用户有都行

    可以看到,不管是001的,755的,都找到了

    [root@centos7 tmp]# find /tmp/ -perm /111  -type f -print0 | xargs -0 ls -ldh
    -rwxr--r-- 1 root root   0 Aug  3 11:06 /tmp/10.txt
    -rwxr-xr-x 1 root root   0 Aug  3 11:07 /tmp/6.txt
    ---------x 1 root root   0 Aug  3 11:07 /tmp/8.txt
    ...
    

    例如:查找/etc目录下面所有用户都没有写权限的文件

    取反即可

    [root@centos7 tmp]# find /etc/ ( -not -perm /111 )  -type f -print0 | xargs -0 ls -ldh | more
    -rw-r--r--. 1 root root      850 Nov 14  2018 /etc/abrt/abrt-action-save-package-data.conf
    -rw-r--r--. 1 root root     2.1K Nov 14  2018 /etc/abrt/abrt.conf
    ...
    

    例如:查找/etc目录下面s所有用户都没有写权限的文件

    [root@centos7 tmp]# find /etc/ ( -not -perm /222 )  -type f -print0 | xargs -0 ls -ldh | more
    -r--r--r--. 1 root root  460 Apr 11  2018 /etc/dbus-1/system.d/cups.conf
    ----------  1 root root  819 Aug  2 15:04 /etc/gshadow
    ----------. 1 root root  828 Aug  2 15:04 /etc/gshadow-
    ...
    

  • 相关阅读:
    数据结构笔记
    简单数学
    分析代码练习--长期目标
    C#基础--面向对象计算器
    经常喜欢看的网站
    C#基础--面向过程计算器
    C#中的五个访问修饰符
    SQLServer 游标详解
    快速产生大量顺序数字序列
    VSCode 必装的 10 个高效开发插件
  • 原文地址:https://www.cnblogs.com/uscWIFI/p/11294204.html
Copyright © 2020-2023  润新知