当前位置: 首页>>技术教程>>正文


unix – chmod:无法读取目录“。”:权限被拒绝

, ,

问题描述

我试图递归更改目录和sub-directories的”data”目录的权限,并遇到以下错误。有人可以提供以下错误的输入吗?

<username:/local/mnt/workspace/data>chmod -R 0644 .
chmod: cannot read directory `.': Permission denied

最佳方案

目录需要执行权限集才能查看其内容。

http://content.hccfl.edu/pollock/AUnix1/FilePermissions.htm

You can think of read and execute on directories this way: directories are data files that hold two pieces of information for each file within, the file’s name and it’s inode number. Read permission is needed to access the names of files in a directory. Execute (a.k.a. search) permission is needed to access the inodes of files in a directory, if you already know the file’s name.

当您将目录权限更改为644时,尽管您可以读取该目录以查看其存在,但是您无法读取该目录中的文件。

您需要这样做:

$ chmod -R 0755 .

如果您只想关闭字符串,则更好的方法可能是使用字符串权限

否则,您可以查看目录,但不能访问该目录中的信息。

您最好使用相对权限而不是绝对权限:

$ chmod -R go-w .

将从群组和其他群组中删除写许可权,但不会触摸执行许可权。

您还可以仅使用find设置目录或设置文件:

$ find . -type d -exec chmod 755 {} \;

这只会触摸目录,在所有目录上设置读取和执行权限,并为所有者设置写权限。这样,您就不会对文件本身设置执行权限。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/7848.html,未经允许,请勿转载。