I just learned something that shocked me, because I did not have a clue it was a fact.If I have a directory with the following permissions:user@host:~$ ls -la testdirtotal 8drwxrwxrwx  2 user user 4096 Mar  3 20:36 .drwx------ 34 user user 4096 Mar  3 20:36 ..-rw-r--r--  1 user user    0 Mar  3 20:36 testfile 1-rw-r--r--  1 user user    0 Mar  3 20:36 testfile 2Even though the files testfile 1 and testfile 2 have write permissions only for the owner everyone can write on them.Until now, I thought that the directories' permissions only affected the directory itself.So now for my question - what good are file permissions on files, if everything seems to be set by the directories' permissions that the files reside in?==== EDIT 1 ====On the other hand look at these permissions:[user@geruetzel2 default]$ ls -latotal 24drwxr-xr-x.  2 root root   41 Dec 19 23:07 .drwxr-xr-x. 96 root root 8192 Mar  3 20:28 ..-rw-r--r--.  1 root root  354 Dec 19 23:07 grub-rw-r--r--.  1 root root 1756 Nov 30 19:57 nss-rw-------.  1 root root  119 Mar  6  2015 useraddIf I do a cat useradd as non-root here, I get a permission denied error. Why is that? The direcory has read permissions for other so it should be readable? There seems to be a difference between the two examples I gave but I don't see the reason for the different behavior.
How do permissions on a directory affect files in it?
files;permissions;directory
The directory permissions only affect the content of the directory. So anybody with write permissions on the directory can e.g. delete files or folders in that directory, even if the permissions of the files or folders are set to have no write access.It maybe makes it easier to understand if you once open the folder with vi or any other text editor. In Unix and Linux Everything is a file.If you for example edit a file with vi, it will not edit the file inplace but make a copy and delete the original when saved.On the other hand, the user not owning the file couldn't echo directly into that file.  