Do you familiar with the option "-perm" of "find" ? I'd like to give some translation to "man find".
'-perm' option is related to file's permission. There are four kinds of parameters that '-perm' option can take :
-perm mode -perm -mode -perm /mode -perm +mode (deprecated)
-perm mode 1 -perm mode 2 File's permission bits are exactly mode (octal or symbolic). 3 Since an exact match is required, if you want to use this form 4 for symbolic modes, you may have to specify a rather complex 5 mode string. For example -perm g=w will only match files which 6 have mode 0020 (that is, ones for which group write permission 7 is the only permission set). It is more likely that you will 8 want to use the `/' or `-' forms, for example -perm -g=w, which 9 matches any file with group write permission. See the EXAMPLES 10 section for some illustrative examples. 11 12 # 文件的权限位需要被精确匹配(八进制或者字符表示)。 13 # 比如,-perm g=w只匹配权限是0020的文件(文件的权限中,只有group用户的写权限被赋予了。) 14 # 但其实你可能是想用 '/' '-'这两种形式的意思。 15 # 比如, -perm -g=w,会匹配group用户被赋予了写权限的所有文件。 16 # [[其它权限也被赋予了也没关系,'-'不要求精确匹配。]] 17 # 详细的解说,参见 EXAMPLES 部分。
-perm -mode 1 -perm -mode 2 All of the permission bits mode are set for the file. Symbolic 3 modes are accepted in this form, and this is usually the way in 4 which would want to use them. You must specify `u', `g' or `o' 5 if you use a symbolic mode. See the EXAMPLES section for some 6 illustrative examples. 7 8 # mode中列出的权限都被满足的文件。 9 # [[mode表示的权限是某个文件的权限的子集。]] 10 # 字符形式表示的mode这种情况下也能用,而且常用。 11 # 用字符形式的时候,必须要指明'u','g','o'。 12 # 详细的解说,参见 EXAMPLES 部分。 13
-perm /mode 1 -perm /mode 2 Any of the permission bits mode are set for the file. Symbolic 3 modes are accepted in this form. You must specify `u', `g' or 4 `o' if you use a symbolic mode. See the EXAMPLES section for 5 some illustrative examples. If no permission bits in mode are 6 set, this test currently matches no files. However, it will 7 soon be changed to match any file (the idea is to be more con- 8 sistent with the behaviour of -perm -000). 9 10 11 12 # 对某个文件,如果mode表示的权限中任何一种被赋予了,这个文件就被匹配了。 13 # 目前,如果mode中什么权限也没有,就匹配不到任何文件。 14 # 但不久以后,就会被修改成可以匹配任何文件。 15 #(修改后看起来更合理。和 -perm -000 的行为更一致。) 16 # [[好像什么都不匹配挺正确的,-perm /777 才应该匹配所有文件。]] 17
-perm +mode 1 -perm +mode 2 Deprecated, old way of searching for files with any of the per- 3 mission bits in mode set. You should use -perm /mode instead. 4 Trying to use the `+' syntax with symbolic modes will yield sur- 5 prising results. For example, `+u+x' is a valid symbolic mode 6 (equivalent to +u,+x, i.e. 0111) and will therefore not be eval- 7 uated as -perm +mode but instead as the exact mode specifier 8 -perm mode and so it matches files with exact permissions 0111 9 instead of files with any execute bit set. If you found this 10 paragraph confusing, you're not alone - just use -perm /mode. 11 This form of the -perm test is deprecated because the POSIX 12 specification requires the interpretation of a leading `+' as 13 being part of a symbolic mode, and so we switched to using `/' 14 instead. 15 16 # 这种形式被弃用了,用/mode来代替了。 17 # 继续使用"+mode",并且使用字符形式的mode,会导致奇怪的结果。 18 # 比如,'+u+x' 是一个合法的字符形式的mode(数字表示是0111)[[的确是0111,待研究]] 19 # 但是,会被解释成 -perm mode形式,而不是 -perm +mode形式。 20 # 所以,会精确匹配权限是0111的文件,而不是有一个可执行权限就可以。 21 # 如果觉得这段有点绕,没关系,很多人都觉得绕。 22 # 只要记住用/mode代替+mode就可以了。 23 # -perm +mode被弃用,是因为POSIX标准要求第一个加号被解释为mode的一部分。 24 # 所以,我们用'/'代替了'+'。
Here are examples , pay more attention on the leading symbols among 'mode', '-mode' and '/mode'。
examples 1 find . -perm 664 2 3 Search for files which have read and write permission for their owner, 4 and group, but which other users can read but not write to. Files 5 which meet these criteria but have other permissions bits set (for 6 example if someone can execute the file) will not be matched. 7 # 精确搜索权限是664的文件。 8 9 find . -perm -664 10 11 Search for files which have read and write permission for their owner 12 and group, and which other users can read, without regard to the pres- 13 ence of any extra permission bits (for example the executable bit). 14 This will match a file which has mode 0777, for example. 15 16 17 # 搜索满足权限664的文件,不管是不是有多余的权限被赋予了。 18 # 比如,0777权限的文件也会被匹配。 19 20 find . -perm /222 21 22 Search for files which are writable by somebody (their owner, or their 23 group, or anybody else). 24 25 26 # 某个文件,如果owner,group,other中,有一个有写权限,这个文件就被匹配。 27 28 find . -perm /220 29 find . -perm /u+w,g+w 30 find . -perm /u=w,g=w 31 32 All three of these commands do the same thing, but the first one uses 33 the octal representation of the file mode, and the other two use the 34 symbolic form. These commands all search for files which are writable 35 by either their owner or their group. The files don't have to be 36 writable by both the owner and group to be matched; either will do. 37 38 39 # 上面的三个命令的作用是一样的,owner,group中,有一个有写权限,这个文件就被匹配。 40 # 不需要owner和group都有写权限。 41 42 find . -perm -220 43 find . -perm -g+w,u+w 44 45 Both these commands do the same thing; search for files which are 46 writable by both their owner and their group. 47 # 这两个命令的作用是一样的,owner和group都有写权限,有多余的权限没关系。 48 49 find . -perm -444 -perm /222 ! -perm /111 50 find . -perm -a+r -perm /a+w ! -perm /a+x 51 52 These two commands both search for files that are readable for every- 53 body ( -perm -444 or -perm -a+r), have at least one write bit set ( 54 -perm /222 or -perm /a+w) but are not executable for anybody ( ! -perm 55 /111 and ! -perm /a+x respectively). 56 # 所有人都可读,owner,group,other有一个可写,所有人都不可执行的文件。 57
|