In fact, I would like to ask more general question -- "what does write permission for a directory allow you to do exactly?" -- but let's approach it with a concrete example.
It is a long question, if you are in a hurry read the bold -- it should cover the main part.
r, read -- reading of the directory's content (filenames inside)
w, write -- changing the directory's attributes (e.g. modification time) and creating/renaming/removing entries inside
x, search -- accessing files inside, you have access to the inode of the file, hence you can reach it's actual content
My problem is with the description of
w. What directory's attributes does it give you access to? I cannot create/rename/remove a file inside a directory with only write permission:
I make a directory (
tdir/) and a file inside (
chmod -x-r tdir/,
mv tdir/afile tdir/af,
touch tdir/newfile -- all fail with permission denial, unless I set
x permission to the directory as well.
x alone doesn't give you the permission to create/rename/remove files inside the directory.
In order to do that you need both
touch tdir does change the modification time of the directory with
I would rephrase the sources above this way for the compliance with the issue: a directory's
r allows you to see the filenames inside, but no access to the actual file (to the inode);
x gives you access to the inodes of the files (which means you can see their permissions and, according to it, have access to the contents), but you still cannot change anything in the directory; directory is actually some sort of a file and to change something in it you need the
Thus, when you are changing something in the directory you need
w permission. If your change requires inodes of the files in the directory -- you need
x as well.
It explains why you cannot remove a file inside a directory with
w only: when removing a file you need to reduce the link count of the inode by 1 -- you need to know the inode -- thus you need
x for the directory.
But why do you need
x for creating (you could ask the system to create a file without exposing the inode?) and renaming/moving the file (when you move a file you don't change it in any way, you only change the records inside the directories and their inode counts?)?
Maybe it is just an implementation thing? I.e. indeed you don't need the inode for renaming/creating files -- you need only filenames and
w permission; but inode and filename constitute one record in the directory; thus changing the filenames = changing the records = kind of accessing the inodes.
And also what attributes do directories have besides modification time, permissions and files records? What else in the directory can you change with