【问题标题】:Linux Command Line - List all non-accessible files and foldersLinux 命令行 - 列出所有不可访问的文件和文件夹
【发布时间】:2014-10-17 19:45:43
【问题描述】:

我正在尝试列出我无权读取和修改的所有文件和文件夹。

谢谢

【问题讨论】:

    标签: linux command-line find


    【解决方案1】:

    文件确实具有三种权限。一份用于文件的所有者,一份用于文件所属的组成员,一份用于所有人。每个人都不能读/写的文件不能被你的一个组读/写,也不能被你的用户读/写,可以使用这样的查找实用程序找到:

    $ find / '( -not -perm -o+w,o+r ) -and ( -not -group <groupname> -perm -g+w,g+r ) -and ( -not -user <username> -perm -u+w,u+r )'
    

    如果您必须检查更多组,您可以在第二个括号内扩展该术语:

    $ find / '( -not -perm -o+w,o+r ) -and ( -not -group <groupname> -perm -g+w,g+r -not -group <group2> ) -and ( -not -user <username> -perm -u+w,u+r )'
    

    【讨论】:

      【解决方案2】:

      使用 find 列出所有文件

      find searchpath
      

      忽略输出,因为只有错误才是您感兴趣的。

      find searchpath >/dev/null
      

      使用 awk 获取所有文件的漂亮列表

      find searchpath 2>&1 >/dev/null | awk '{ print substr($2,2,length($2)-3) }'
      

      请注意,这假定所有文件的名称中都没有空格,要解决这个问题,只需更改 awk sctipt。

      【讨论】:

      • OP 想要所有他无法读取的 文件 和目录。这种方法只会给他目录。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      • 2018-04-19
      • 2013-02-19
      • 2018-09-01
      相关资源
      最近更新 更多