Permissions – When to Use Directory with +x Permission and Parents Without

permissions

Say I have a folder called folder in the following path:

my_path = /a/b/c/d/e/folder

and a file called file in that folder.

Then, say I run this command to remove group permissions under /a/

> chmod g-rwx -R /a/

Now, say I give +rx permissions to folder:

> chmod g+rx /a/b/c/d/e/folder

Then, if a second user in my group runs:

> ls /a/b/c/d/e/folder

or

> cat /a/b/c/d/e/folder/file 

she gets permission errors, and as far as I understand this is because I need to provide g+x access to to all the parents of folder. My question then is, when or why would it ever be useful to give +x permission to a directory whose parent does not have it?

Thanks

Best Answer

Most of the time, if you want to block access and usage of an entire directory (including its subdirectory), you can do it by removing it (non-recursively) -x. Therefore, you may have left subdirectories with +x, without doing any harm.

Keeping the permissions on the subdirectories can be useful for a number of reasons (especially when -x doesn't apply to everyone but at least one user can still do something).

For example, you could block usage of the container directory temporarily, while doing other changes to the permissions within that directory structure, and then re-enable access to the whole tree in one operation (giving +x to the top level directory).

You could also have a situation where a script (not necessarily run by the owner) backs up the directory tree in a temporary location (which shouldn't be readable by others) and puts everything in a tar file, preserving the permission settings of the content of the directory.

Related Question