find命令-perm参数

find命令-perm参数

2023年7月26日发(作者:)

find命令-perm参数-perm参数有3种类型1. -perm 644这种类型是精准匹配,只把权限是644的⽂件和⽬录取出来[root@centos6 ~]# find . -perm 644 -ls1703939 4 -rw-r--r-- 1 root root 3384 Jan 23 20:24 ./1703940 4 -rw-r--r-- 1 root root 18 May 20 2009 ./.bash_logout1703941 4 -rw-r--r-- 1 root root 176 May 20 2009 ./.bash_profile1703943 4 -rw-r--r-- 1 root root 100 Sep 23 2004 ./.cshrc1703938 12 -rw-r--r-- 1 root root 8901 Jan 23 20:26 ./1703948 4 -rw-r--r-- 1 root root 6 Jan 24 02:34 ./aaa1703944 4 -rw-r--r-- 1 root root 129 Dec 4 2004 ./.tcshrc1703942 4 -rw-r--r-- 1 root root 176 Sep 23 2004 ./.bashrc[root@centos6 ~]#

2. -perm -644 这种类型的匹配意思是:所有者的权限⾄少是读写,并且群组的权限⾄少是读,其他⼈的权限⾄少是读,三个是与的关系。但是所有者的权限可以是读写执⾏。只要包括读写权限即可,所以例如权限777的⽂件也可以匹配,因为它包含644权限。

[root@centos6 ~]# find . -perm -644 -ls 1703953 4 -rwxr-xr-x 1 root root 25 Feb 9 23:44 ./ 1703939 4 -rw-r--r-- 1 root root 3384 Jan 23 20:24 ./ 1703940 4 -rw-r--r-- 1 root root 18 May 20 2009 ./.bash_logout 1703941 4 -rw-r--r-- 1 root root 176 May 20 2009 ./.bash_profile 1703943 4 -rw-r--r-- 1 root root 100 Sep 23 2004 ./.cshrc 1703938 12 -rw-r--r-- 1 root root 8901 Jan 23 20:26 ./ 1703949 4 drwxrwxrwx 2 root root 4096 Mar 20 11:48 ./test 1703948 4 -rw-r--r-- 1 root root 6 Jan 24 02:34 ./aaa 1703944 4 -rw-r--r-- 1 root root 129 Dec 4 2004 ./.tcshrc 1703942 4 -rw-r--r-- 1 root root 176 Sep 23 2004 ./.bashrc [root@centos6 ~]#

3.-perm +644(centos7 -perm /644) 这种写法的意思是:只要所有者满⾜读写权限,或者群组满⾜读权限,所有者满⾜读权限。就是说只要满⾜⼀个条件就可以匹配出来,所有者权限为7的也可以匹配出来。

[root@df~/test 11:56:09]$ ll total 0 -rwxrwxrwx. 1 root root 0 Mar 20 11:03 a -rwxrw-rwx. 1 root root 0 Mar 20 11:03 b -rwxr--r--. 1 root root 0 Mar 20 11:03 c ----------. 1 root root 0 Mar 20 11:03 d drwxr-xr-x. 2 root root 42 Mar 20 11:51 test [root@df~/test 11:56:14]$ find . -perm /111 . ./a ./b ./c ./test [root@DengFan ~/test 11:56:24]$

可以看出来⾄少有1位执⾏权限就可以匹配出来! 假如我要取⼀个⽬录下所有⼈都没有写权限的⽂件和⽬录该怎么取呢?按照通常的想法是find . ! -perm -111。但是这条命令的意思是取出⾄少有⼀位没有执⾏权限的⽂件和⽬录! 然后测试⼀下!的结果,会发现还是有带执⾏权限的⽂件 [root@df ~/test 12:01:03]$ find . ! -perm -111 -ls

100679105 0 -rwxrw-rwx 1 root root 0 Mar 20 11:03 ./b 100679106 0 -rwxr--r-- 1 root root 0 Mar 20 11:03 ./c 100679107 0 ---------- 1 root root 0 Mar 20 11:03 ./d 694655 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/a 890201 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/b 890202 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/c 890203 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/d [root@df ~/test 12:01:10]$ 正确做法是对/111取反,逻辑是对⾄少有1位执⾏权限取反,就是所有位都没有执⾏权限 [root@df~/test 12:04:12]$ find . ! -perm /111 -ls 100679107 0 ---------- 1 root root 0 Mar 20 11:03 ./d 694655 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/a 890201 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/b 890202 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/c 890203 0 -rw-r--r-- 1 root root 0 Mar 20 11:51 ./test/d [root@df~/test 12:05:23]$

总结: 取出所有没有执⾏权限的⽂件:find . ! -perm /111 取出⾄少⼀位执⾏权限的⽂件:find . ! -perm -111

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1690361260a337817.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信