umask

Hi,

Please, let me know how the umask is working? As per my understanding is aprt from subtracting from 666/777, logical gate operation is performing.

Ex: If I set uname 011, it gave the permission like 666 for file. Request you to explain which gate's operation performed.

$uname 011
$uname
0011
$vi abc
$ls -l abc
-rw-rw-rw- 1 unixguy staff 29 Jan 26 14:03 abc

Regards,
Naga:cool:

If you copy and pasted from your shell, you entered the wrong command (uname instead of umask).
A umask of 011 should give permissions of -rw-rw-rw- for a file

Hi,

Sorry for the inconvenience, Once again with umask

Please, let me know how the umask is working? As per my understanding is aprt from subtracting from 666/777, logical gate operation is performing.

Ex: If I set uname 011, it gave the permission like 666 for file. Request you to explain which gate's operation performed.

$umask 011
$umask
0011
$vi abc
$ls -l abc
-rw-rw-rw- 1 unixguy staff 29 Jan 26 14:03 abc

May I know why it should give -rw-rw-rw- if i set 011? As well if i see 000 also differ, may I know how the kernel is behaving?

Thanks,
Naga:cool:

The umask describes what file-access bits to always eliminate when creating a file, where 1 is execute, 2 is write, and 4 is read. a umask of 777 will always remove all bits, 666 will remove read and write, 000 won't clear any bits at all, etc. A umask of 000 will usually result in rw-rw-rw just because what created the file never asked for the execute bit to be set in the first place; the umask will never give more bits than what the program asked for, just remove specific bits.

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