chmod: cannot read directory `.': Permission denied [closed]

匿名 (未验证) 提交于 2019-12-03 02:46:02

问题:

I am trying to recursively change the permission of directories and sub-directories for "data" directory and running into following error..can someone provide inputs on the below error?

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

回答1:

Directories need the execute permission set in order to see their contents.

From 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.

When you change a directory permission to 644, you are unable to read the files in that directory although you can read that directory to see it exists.

You need to do this:

$ chmod -R 0755 . 

A better way might be to use string permission if you simply want to turn off

Otherwise, you can see the directory, but not access the information in that directory.

You maybe better off using relative permissions instead of absolute permissions:

$ chmod -R go-w . 

Will remove write permission from group and other, but not touch execute permission.

You can also use find just to set the directories or just to set files:

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

This will only touch directories, setting read and execute permission on all directories and setting write permission for the owner. This way, you're not setting execute permission on files themselves.



回答2:

I would guess that since you are using recursion that you are trying to CD to a directory that does not have execute permission for you.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!