Solved

umask

Posted on 2004-08-12
3
487 Views
Last Modified: 2010-04-21
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.
0
Comment
Question by:decentswati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11783927
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
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 50 total points
ID: 11796036
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
 
LVL 1

Author Comment

by:decentswati
ID: 11799398
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Optimize bash script 20 477
understanding folder structure inside an rpm 2 79
What is the timeframe of this cron job? 2 147
Use Powershell script to ftp 10 127
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question