I've read here that in order to create a file inside a directory in Linux, one should have write permission to that directory. However when examining this (in Ubuntu Server 14) it did not worked.
osboxes@osboxes:~$ mkdir mydir
osboxes@osboxes:~$ chmod 200 mydir
osboxes@osboxes:~$ ls -l
d-w------- 2 osboxes osboxes 4096 May 25 09:52 mydir
osboxes@osboxes:~$ touch mydir/myfile
touch: cannot touch 'mydir/myfile': Permission deniedonly after adding execute permissionto mydir I could touch that file. So execute permissions are also needed in order to touch a file?
EDIT: from @Pablo Bianchi ref I learn that
Write (w)
The ability to rename files in the directory, create new files, or delete existing files, if you also have Execute permissions. If you don't have execute perms, then write perms are meaningless."
So I guess that execute perms are ndeed required in order to use write perms to create new files.
42 Answers
A directory is nothing else than a file, but it is a special file which contains a list of hardlinks to the files and subdirectories (which are also indeed files).
If you have read permissions for a directory, you are able to read the list of hardlinks.
If you have write permissions for a directory you are able to modify the list of hardlinks.
The execute permission is like a door to the next level, if you have execute permission, the door is open. If you don't have execute permission, the door is closed.
If you want to create a file in a directory, you need to be able to modify the list of hardlinks, thus you need write permission for the directory. But that's just a directory-entry, the file itself will reside behind the door, so you need execute permission to open the door.
Imagine a room with a table inside it. On the door is a list with the furniture in the room, the list contains only the word 'table'. Now you want to add a chair to the table in the room. You add the word 'chair' to the list on the door. And you need to open the door to bring the chair inside.
1From the start, after creating your directory, you should have all the persimissions for yourself to read write and execute.
Right after mkdir if you use ls -l command the output should be like this
drwxr-xr-x 2 osboxes osboxes 4096 May 25 09:52 mydirIn order to return to that configuration you could run :
chmod 755 mydirIf you just want to remove all permsissions to anyone but you
chmod go-rx mydirIt could be useful to read more about Understanding Linux Permissions and chmod Usage
1