chmod: cannot read directory `.': Permission denied

carte blanche picture carte blanche · Apr 4, 2013 · Viewed 83.4k times · Source

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

Answer

David W. picture David W. · Apr 4, 2013

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.