I want to set permissions such that whenever a directory is created by a 'user' then its default permissions should be 775.
But when that 'user' creates a new file then default permissions should be 774.
How can I achieve this?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
I'm not sure how to get those exact permissions, but using umask, you can set the permissions for files and directories within 111 of each other.
This site explains how it works: http://kb.iu.edu/data/acge.html
would give you 775 for directories and 664 for files. Not exactly what you're looking for, but you might be able to figure something out related to umask.
The default umask can be found in /etc/profile. This can be overridden for each user by editing the umask in ~/.profile.
Note: The default umask for most unix machines is 022, which gives you: 644 (rw-r--r--) for files and 755 (rwxr-xr-x) for directories.
The default file permissions on newly created files and directories are a standard permission (
rw-rw-rw for files,
rwxrwxrwx for directories) subtracting the current umask setting. A umask setting of 000 would keep the standard permissions, whereas a setting of 777 would remove all permissions.
The three numbers in the umask represent user, group and anyone permissions respectively. The number represents three binary digits whether to remove a specific permission or not.
d - rwx ------- 0 - 000 (rwx) 1 - 001 (rw-) 2 - 010 (r-x) 3 - 011 (r--) 4 - 100 (-wx) 5 - 101 (-w-) 6 - 110 (--x) 7 - 111 (---)
To calculate which permissions a new file will have given a certain umask, start with the default permission and subtract the umask.
orig rwx rwx rwx (777, default directory permission) umask 000 010 010 (022) result rwx r-x r-x (755) orig rw- rw- rw- (666, default file permission) umask 000 010 010 (022) result rw- r-- r-- (644) orig rwx rwx rwx (777, default directory permission) umask 000 000 010 (002) result rwx rwx r-x (775) orig rw- rw- rw- (666, default file permission) umask 000 000 010 (002) result rw- rw- r-- (664)