如何在Unix上查找权限错误的文件?


14

我正在寻找一种搜索目录或目录的方式,并列出对公共目录具有错误权限的所有文件。

Answers:


15

您的问题可以更清楚地陈述,尤其是。您对公共目录的“错误权限”是什么意思?

假设您希望目录为755,普通文件为644,我将这样做:

$ find \! -perm 644 -type f -o \! -perm 755 -type d

-o做什么?这是否意味着类似OR?


3
在这种特殊情况下,鉴于多种级别的查找设置,RTFM并不是一个很有帮助的答案。试图弄清楚-o是与-type还是-perm相关联的,这尤其令人困惑。
Lighthart 2015年

我允许我不同意。问题是“ -o做什么?它表示类似OR的意思吗?”。手册页可以完美地回答:“ expr1 -o expr2或;如果expr1为true,则不评估expr2。”
2015年

顺便说一句。有关优先级的问题在手册页的同一段中进行了处理:“按优先级递减的顺序列出了运算符”和“将两个表达式用隐含的'和'连接在一起;如果expr1是,则不评估expr2假。”)。
2015年

5

这对我有用

find .  \! -perm +755

\!标志表示不是,并且该-perm选项使用常规的chmod选项


3

一切都取决于您认为什么是“错误权限”。man find通过定义在给定权限下查找文件/目录的方式来帮助您:

   -perm -mode
          All of the permission bits mode are set for the file.  Symbolic modes are
          accepted in this form, and this is usually the way in which would want to
          use them.  You must specify ‘u’, ‘g’ or ‘o’ if you use a  symbolic  mode.
          See the EXAMPLES section for some illustrative examples.

   -perm /mode
          Any of the permission bits mode are set for the file.  Symbolic modes are
          accepted in this form.  You must specify ‘u’, ‘g’ or ‘o’  if  you  use  a
          symbolic  mode.  See the EXAMPLES section for some illustrative examples.
          If no permission bits in mode are set, this test matches  any  file  (the
          idea here is to be consistent with the behaviour of -perm -000).

   -perm +mode
          Deprecated,  old  way  of  searching for files with any of the permission
          bits in mode set.  You should use -perm /mode instead. Trying to use  the
          ‘+’  syntax with symbolic modes will yield surprising results.  For exam‐
          ple, ‘+u+x’ is a valid symbolic mode (equivalent to +u,+x, i.e. 0111) and
          will  therefore  not be evaluated as -perm +mode but instead as the exact
          mode specifier -perm mode and so it matches files with exact  permissions
          0111  instead of files with any execute bit set.  If you found this para‐
          graph confusing, you’re not alone - just use -perm /mode.  This  form  of
          the -perm test is deprecated because the POSIX specification requires the
          interpretation of a leading ‘+’ as being part of a symbolic mode, and  so
          we switched to using ‘/’ instead.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.