对于给定的目录,如何检查哪些文件在组部分具有特定的权限标志?

对于给定的目录,如何检查哪些文件在组部分具有特定的权限标志?

我有一个目录,我想列出所有有权在其组部分写入的文件,无论它们属于哪个组。

另外,如何为整个文件系统完成它?

答案1

您可以find-perm谓词一起使用。从man find(POSIX):

-perm [-]mode

      The mode argument is used to represent file mode bits. It  shall
      be identical in format to the symbolic_mode operand described in
      chmod() , and shall be interpreted  as  follows.   To  start,  a
      template shall be assumed with all file mode bits cleared. An op
      symbol of '+'  shall  set  the  appropriate  mode  bits  in  the
      template;  '-'  shall  clear the appropriate bits; '=' shall set
      the appropriate mode bits, without regard  to  the  contents  of
      process' file mode creation mask. The op symbol of '-' cannot be
      the first character of mode;  this  avoids  ambiguity  with  the
      optional leading hyphen. Since the initial mode is all bits off,
      there are not any symbolic modes that need to  use  '-'  as  the
      first character.

If  the  hyphen is omitted, the primary shall evaluate as true when the
file permission bits exactly match the value of the resulting template.

Otherwise, if mode is prefixed by a hyphen, the primary shall  evaluate
as  true  if at least all the bits in the resulting template are set in
the file permission bits.

因此,您可以尝试:

find /some/path/ -type f -perm -g=w

-type f测试常规文件。对于整个文件系统,替换/some/path/.

相关内容