umask in *nix operating systems

Source: http://askubuntu.com/questions/44542/what-is-umask-and-how-does-it-work

To calculate for the umask, unlike file system permissions. The octal umasks are calculated via the bitwise AND of the unary complement of the argument using bitwise NOT. The octal notations are as follows:

Octal value : Permission
0 : read, write and execute
1 : read and write
2 : read and execute
3 : read only
4 : write and execute
5 : write only
6 : execute only
7 : no permissions

Then you can calculate to set umask proper permissions such:

$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file

drwx------ 2 amrx amrx 4096 2011-03-04 02:05 dir1
-rw------- 1 amrx amrx 0 2011-03-04 02:05 file

Calculating The Final Permission For Files

You can simply subtract the umask from the base permissions to determine the final permission for file as follows:

666 – 022 = 644
  • File base permissions : 666
  • umask value : 022
  • subtract to get permissions of new file (666-022) : 644 (rw-r–r–)

Calculating The Final Permission For Directories

You can simply subtract the umask from the base permissions to determine the final permission for directory as follows:

777 – 022 = 755
  • Directory base permissions : 777
  • umask value : 022
  • Subtract to get permissions of new directory (777-022) : 755 (rwxr-xr-x)

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *