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?

  • I was just reading that 'umask' can be used. But I have no idea how can I set different default permissions for file and different for directories. – peakit Sep 1 '09 at 17:25
  • Do you really want files to default to being executable? That's a disaster waiting to happen. – Cascabel Sep 1 '09 at 17:29
  • Thanks Jefromi. Is there a way that I can define that default group for all files and directories should be myself? Then it should not be a problem.. right? – peakit Sep 1 '09 at 17:37

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

For example:

umask 002

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.

| improve this answer | |
  • The link which you gave cleared my doubt that for directories the umask is subtracted from 777 and for files from 666. Thanks. – peakit Sep 1 '09 at 17:47

Umask explained

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)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.