4
3
Do I correctly understand permission to directories in Linux/Unix?
If your directory has only
r
(read) permission you are allowed to see the content of the directory (which files are located there) but you cannot do it because you cannot go (cd
) to this directory (because of the absence ofx
permissions). You also cannot see the content of the directory (which files are located there) from outside of the directory (for example byls directoryname/*
). You also will be unable to read (see) content of files located in such a directory usingcat
andmore
commands (even if you have permissions to read these files). You also will be unable to modify (write) files (even if you have write permissions to them) if these files are located in such a directory (no matter what you trycat >>
,echo >>
,cp
or some text editor). So, from my point of view, to have onlyr
permissions to a directory is equivalent to having absolutely no permissions to the directory.If your directory has only
x
(execute) permissions you are allowed to go (cd
) into the directory but you are not allowed to see (ls
) the content of the directory (because you do not have permissions to read the directory). If a directory has onlyx
permission and it contains a file for which you haver
(read) andw
(write) permissions, you still well be unable to open this file with (at leas some) text editors (for examplemcedit
). But you will be able to read context of the file using such commands ascat
ormore
. You alls will be able to modify content of the file usingecho >>
orcat >>
. So, it seems to me, that it isx
what allows users to "read" and "write" existing files in the directory (if files have the corresponding permissions too).If a directory has
r
andx
permissions but now
(write) permissions, you cannot change content of the directory (set of files which are located there). For example you cannot create a new file there or remove existing in the directory. But you still are allowed to change content of existing files. So, you needw
permissions to create or remove files in the directory.Added:
It is also interesting to mention that
w
permission to the directory is necessary but not sufficient to create and delete files in the directory. If a directory has onlyw
permission you will be unable to add/remove files from/to the directory. To be able to do so, you need to havex
permission to the directory (additionally tow
permission).
You can think of the directory as a file, which is ``edited'' when you add/remove files from the directory. – casualuser – 2010-02-28T21:52:36.880