The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




Thread: umask
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 06-29-2009
kurinchiblogger kurinchiblogger is offline
Registered User
  
 

Join Date: Jun 2009
Location: Canada
Posts: 1
umask explanation

I thought to post the information related to umask which i have read it from sites so that it might be helpful to someone who comes across this thread ...

$ umask
022 (this is the default value in my system)

For files, the permission settings are 0666 and for directories it is 0777


Having known the umask value, try creating a directory and a file and check what the file settings are

$ mkdir tempdir1

$ ls -l
drwxr-xr-x 2 root root 4096 2009-06-29 10:42 tempdir1

$ touch tempfile1

$ ls -l
drwxr-xr-x 2 root root 4096 2009-06-29 10:42 tempdir1
-rw-r--r-- 1 root root 0 2009-06-29 10:43 tempfile1


Change the umask and again create a directory and a file and check the file permission settings

$ umask 027
$ umask
0027
$ mkdir tempdir2
$ ls -l
total 12
drwxr-x--- 2 root root 4096 2009-06-29 10:40 tempdir2

$ touch tempfile2
$ ls -l
drwxr-x--- 2 root root 4096 2009-06-29 10:40 tempdir2
-rw-r----- 1 root root 0 2009-06-29 10:40 tempfile2

Now, let us see how the file permission settings are calculated using boolean expression.

For the directories, you need to take the 1's complement of the umask value and perform a logical AND operation with 0777.

For e.g. consider the case where we have umask value of 027 - 0000 0000 0010 0111
1's complement of 027 - 1111 1101 1000

For directories perform logical AND operation with 0777 (0000 0111 0111 0111). So

1111 1101 1000 (1's complement of 027)
0111 0111 0111 (0777)
-------------------
0111 0101 0000 = 0750


For files, perfom logical AND operation with 0666 (0000 0110 0110 0110), so

1111 1101 1000 (1's complement of 027)
0110 0110 0110 (0666)
-------------------
0110 0100 0000 = 0640