8

I have a bunch of media files (that only need to be 644) that were a mix of various permissions. Some were group or global writable so I thought, just to be safe, I'll chmod them all back to 644.

The problem is there is a directory hierarchy and for all the directories that were caught in this ls -l displays them as:

d????????? ? ? ? ?            ? Dirname

If I chmod that to 744, it's fixed.

My question is: What's going on here? Do directories need to be executable?

dessert
  • 39,982
Oli
  • 293,335

2 Answers2

7

As noted in the manpage for chmod with relation to permissions:

The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X)

The executable bit on a folder is explained above as a 'search' permission; i.e. the execute bit merely allows you to access the folder in a file browser or to move to the folder from the terminal by running the cd command or running ls ~/folder to list the files in the folder.

The folder must be executable for the owner, although the superuser would still be able to access the folder as when using sudo any file or directory can be accessed or deleted. In addition, directory and file permissions are explained further in this useful article at Stackoverflow.

It is also important to note that 'executing' the folder doesn't mean you are actually running any code or commands like when a executable binary or script is run.

For a home Desktop user (though perhaps not for your server) most folders within $HOME have the execute permission set for user, group, and other if viewed with stat ~/myfolder (excerpt below):

Access: (0755/drwxr-xr-x)  Uid: ( 1000/    mike)   Gid: ( 1000/    mike)

The standard permissions for folders within $HOME are 755 or 775 and for files they are 644. However, the rest of the filesystem will differ. Again, folders must have the execute bit for the owner or they will not be able to be opened by him. It is important to be careful with chmod when changing permissions and particularly when doing it recursively as the situation can quickly get messed up.

For more information, see man chmod or the Ubuntu manpages online, and this article at Superuser.

dessert
  • 39,982
0

Directories need x bit set (for directory that bit is seen as search bit) to open. Many people discover that when they remove the executable bit with chmod -R on the entire folder, then they cannot access it anymore. To fix this I use tree so I can get only the folder set and avoid the nightmare of having all the files set as executables ( the option for tree is -d List directories only.):

sudo tree -faid dirname | xargs -L1 -I{} sudo chmod +x "{}"

if you don't have tree:

find  dirname -type d -exec chmod +x {} 

Warning!!! you should have this into considerations:

  • using chmod or chown recursive on root / directory or system directories will destroy your OS (actually anything recursive on / directory or system directories is dangerous)

  • this is not a good security practice to set permission bulk like that