umask

HI,
please tell me the use of umask and its working procedure.i know it is for changing permissions of files but how it works and how it is different from chmod.
LVL 1
decentswatiAsked:
Who is Participating?
 
NovaDenizenCommented:
The umask controls the default permissions of files you create.  For instance, my umask is 0022, which means that the write bits for 'group' and 'other' are masked out.  By default, my files are readable by anyone, but writable only by myself.
 $ umask
0022
 $ echo hello > temp
 $ ls -l temp
-rw-r--r--    1 nova  users           6 Aug 13 14:50 temp
 $ chmod +rwx temp
 $ ls -l temp
-rwxr-xr-x    1 nova users           6 Aug 13 14:50 temp*

Notice that the write bits for 'group' and 'other' stay disabled.  The execute bits are off because of the 0022 umask.
 $ chmod 000 temp
 $ ls -l temp
----------    1 nova users           6 Aug 13 14:50 temp
 $ umask 0007
This umask turns off all bits in 'other' by default

 $ chmod +rwx temp
 $ ls -l temp
-rwxrwx---    1 nova users           6 Aug 13 14:50 temp*
chmod pays attention to the umask, and won't turn on bits in the umask unless you specifically tell it to like this:
 $ chmod o+r temp
 $ ls -l temp
-rwxrwxr--    1 nova users           6 Aug 13 14:50 temp*

To sum up:
The umask setting controls the default permissions of files as you create them.  Normal files you create are set to (0666 & ~umask), and executable files you create are set to (0777 & ~umask).
Whenever you do chmod +r, +w, or +x with no user/group/other modifiers, chmod uses the umask when it performs the chmod, and will not turn on the masked off bits.
If you use chmod to explicitly turn on a group of bits, chmod will do what you say and ignore the umask setting.
0
 
brettmjohnsonCommented:
The umask specifies the default DENY permissions for future file creations,
whereas chmod modifies the permissions of existing files.  Note that, since
the umask is a deny mask, its 1s complement is ANDed with the requested
(or implied) permissions to get the final result.

http://librenix.com/?inode=4612
http://unix.about.com/library/glossary/bldef-cmd-umask.htm

Note that one lame-ass tutorial on the net describes the umask value as:
  "The logic behind the number given to umask is not intuitive."
and goes not further.  Why it shows up at the top of google's list is beyond me.

0
 
decentswatiAuthor Commented:
HI both of u,
i am now going to finalize this question.I accept the answer of NovaDenizen because of its clearity.still for the more clearity the 2nd url of Brettmjohnson.thanks for helping me out.
bye-decentswati
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.