Umask questions

Soldato
Joined
7 Apr 2004
Posts
4,212
Hi,

Got a couple of questions about linux umask, I know that for full permissions on files the octal value is 666 and directories is 777, but what i don't understand is how to work out umask values given a permission string.

Say for example say I want new files to be created as rwx r-- r-- (744), How would i calculate the umask value for these permissions?

Secondly, does umask operate on a per directory basis or per user basis?

Thanks,

Jack
 
They are basically 3, 3-bit fields so to work them out you basically need to add up what each bit is 'worth':

rwx rwx rwx
421 421 421

So to set rwx rwx rwx would add up to 7 7 7, rw r r would be 6 4 4 and rwx rx rx would be 7 5 5.

Hopefully that makes sense :)
 
Thanks, but thats just the octal value of the permission string isnt it? Thats not really what im after, sorry if i worded the question badly.

http://en.wikipedia.org/wiki/Umask

So for example:

Assuming the umask has the value 174, any new file will be created with the permissions 602 and any new directory will have permissions 603 because:

666 AND NOT(174) = 602

So with a umask value of 174, you get an octal permission string of 602 for newly created files (rw- --- -w-)


I just dont understand how the logical bitwise maths works to get from 174 to 602 :confused:

Thanks again,

Jack
 
Last edited:
Sorry, I misunderstood your question, it's actually explained really well on that URL you pasted. You basically and the full access permissions (666 or 777 for files and folders) with the 'inverse' of the umask (bitwise NOT).

The example they give on that page is for umask 174 (001 111 100), which when you do a bitwise NOT becomes 110 000 011 which when you AND to 777 for folders (111 111 111) gives 110 000 011 (603), and to 666 for files (110 110 110) gives 110 000 010 (602).

Or have I misunderstood your question again? :p
 
Back
Top Bottom