专题:“find -perm”

 1 find . -perm 664
 2 
 3        Search for files which have read and write permission for their owner, and group, but which other users  can  read  but  not  write  to.
 4        Files which meet these criteria but have other permissions bits set (for example if someone can execute the file) will not be matched.
 5 
 6        find . -perm -664
 7 
 8        Search  for  files which have read and write permission for their owner and group, and which other users can read, without regard to the
 9        presence of any extra permission bits (for example the executable bit).  This will match a file which has mode 0777, for example.
10 
11        find . -perm /222
12 
13        Search for files which are writable by somebody (their owner, or their group, or anybody else).
14 
15        find . -perm /220
16        find . -perm /u+w,g+w
17        find . -perm /u=w,g=w
18 
19        All three of these commands do the same thing, but the first one uses the octal representation of the file mode, and the other  two  use
20        the  symbolic  form.  These commands all search for files which are writable by either their owner or their group.  The files don't have
21        to be writable by both the owner and group to be matched; either will do.
22 
23        find . -perm -220
24        find . -perm -g+w,u+w
25 
26        Both these commands do the same thing; search for files which are writable by both their owner and their group.
27 
28        find . -perm -444 -perm /222 ! -perm /111
29        find . -perm -a+r -perm /a+w ! -perm /a+x
30 
31        These two commands both search for files that are readable for everybody ( -perm -444 or -perm -a+r), have at least one write bit set  (
32        -perm /222 or -perm /a+w) but are not executable for anybody ( ! -perm /111 and ! -perm /a+x respectively).
Man's examples:
f@z ~/testdir/test $ ls -lha
total 24K
drwxr-xr-x  2 f f 4.0K Aug  4 19:34 .
drwxr-xr-x 18 f f 4.0K Aug  4 18:14 ..
-rw------x  1 f f   33 Jul 26 20:10 a.file
-rwxr-xr-x  1 f f   33 Aug  4 18:17 b.file
-rw-r----x  1 f f   33 Aug  4 19:34 c.file
---x--x--x  1 f f   33 Aug  4 19:34 d.file
f@z ~/testdir/test $ find -perm 210
精确匹配权限=210的文件或目录
f@z ~/testdir/test $ find -perm -210
.
./b.file
-:指“交集”或“与”逻辑,即搜索user至少具备写权限,并且group至少具备执行权限的文件或目录;
特别注意概念!!!
这个“-”与“小于”没有关系,另外搜索的逻辑也不是比较权限位数字的大小,而是逐一查看所有的权限位(rwx)是否符合搜索条件;
!!!:搜索条件中为0(即空权限位)的角色权限(本例中为other权限),不作为筛选条件,不参与筛选。
f@z ~/testdir/test $ find -perm /210
.
./a.file
./d.file
./c.file
./b.file
/:指“并集”或“或”逻辑,即搜索user至少具备写权限,或者group至少具备执行权限的文件或目录;
这个“/”与“大于”没有关系,而是逐一查看是否存在任一对应的权限位(rwx)满足搜索条件。
f@z ~/testdir/test $ find ! -perm /210 
!:“取反”逻辑,与“-“搭配,意指搜索条件中标注的权限位中,若任一一位为空,即作为符合条任的结果返回。
f@z ~/testdir/test $ find ! -perm -210
./a.file 
.
/d.file
.
/c.file
!:“取反”逻辑,与“/”塔配,意指搜索条件中标注的权限位,若全部不为空,即拥有对应的权限,则返回结果。
原文地址:https://www.cnblogs.com/hadex/p/5738004.html