LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-07-2005, 02:40 PM   #1
osmansm
LQ Newbie
 
Registered: Dec 2005
Location: New York
Distribution: RedHat 9
Posts: 2

Rep: Reputation: 0
what is umask


Dear Friend:
i am a new user for linux i study it by myself and i want to ask two question
1) what is umask?
2) what is the relationship between umask and file
permission

Thanks
For your attention
 
Old 12-07-2005, 02:45 PM   #2
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
It basically determines what the permissions are on files you create.
Basically your umask is defined as a number like 022 and then this number is subtracted from 777 or 666 (depending on if it's a directory or a file) to new files created. So if you're umask is 022 and you create a file then 666 - 022 = 644 so new files are created with rwxr--r-- permissions.

Clear as mud?
 
Old 12-07-2005, 03:08 PM   #3
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
They're not really "substracted". These bits are just switched off. You can't substract 022 from 600 or 700 or whatever. If details of it matter, they're switched off with AND and NOT, ie: (permissions & ~umask)

See your current octal umask just running "umask" and the effective final permission with "umask -S".

Last edited by primo; 12-07-2005 at 03:11 PM.
 
Old 12-07-2005, 03:49 PM   #4
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Quote:
Originally Posted by primo
They're not really "substracted". These bits are just switched off. You can't substract 022 from 600 or 700 or whatever. If details of it matter, they're switched off with AND and NOT, ie: (permissions & ~umask)

See your current octal umask just running "umask" and the effective final permission with "umask -S".
It's not subtracted from 600 or 700 it is subracted from 666 or 777.
And yes you can use simple subtraction to figure out what your permissions will be. (I'm not saying that the computer actually does a subtraction I'm just saying us mortals can use subtraction to figure it out)
for file permissions:
666 - umask = effective file permissions (same as if you did chmod with the result)
For directories:
777 - umask = effective directory permissions (same as doing chmod with the result)
 
Old 12-07-2005, 05:29 PM   #5
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by Blinker_Fluid
It's not subtracted from 600 or 700 it is subracted from 666 or 777.
Man, this is irrelevant, because you must specify some permissions if you create a file. You may specify ANY permission and the effective one is a result of an AND operation of the specified permissions with the umask's complement, that is tp say: those bits are turned off.

Quote:
And yes you can use simple subtraction to figure out what your permissions will be. (I'm not saying that the computer actually does a subtraction I'm just saying us mortals can use subtraction to figure it out)
for file permissions:
666 - umask = effective file permissions (same as if you did chmod with the result)
For directories:
777 - umask = effective directory permissions (same as doing chmod with the result)
666 or 777 are just cases and they're not generic. The effective permission is the AND of the permission you specified (which may be different) with the umask's complement (~umask). 777 - umask is the same as 777 & ~umask, but the effective permissions take into account the ones you specified. Let's quote the umask(2) manpage:
Quote:
for example, the common umask default value of 022 results in new files being created with permissions 0666 & ~022 = 0644 = rw-r--r-- in the usual case where the mode is specified as 0666)
It's of no help to think of it as being substracted because 666 or 777 aren't used every time.
 
Old 12-07-2005, 05:43 PM   #6
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Time to pull out some man pages (from solaris 10, sorry no access to a linux box at this time)...
Quote:
The user file-creation mode mask is set to ooo. The three
octal digits refer to read/write/execute permissions for
owner, group, and other, respectively (see chmod(1),
chmod(2), and umask(2)). The value of each specified digit
is subtracted from the corresponding ``digit'' specified by
the system for the creation of a file (see creat(2)). For
example, umask 022 removes write permission for group and
other (files normally created with mode 777 become mode 755.
Files created with mode 666 become mode 644).
 
Old 12-07-2005, 06:09 PM   #7
JunctaJuvant
Member
 
Registered: May 2003
Location: Wageningen, the Netherlands
Distribution: OS X
Posts: 488

Rep: Reputation: 31
To osmansm:
http://www.sun.com/bigadmin/content/...rmissions.html

You can find many more pages like that by using google and there is even a (very concise) umask entry in the wikipedia.
Hope that helps.
 
Old 12-07-2005, 06:16 PM   #8
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Man, see what the manpage says. It illustrates the point perfectly. It says "files normally created". See the creat(2) manpage and the open(2) manpage. If you specify 640 instead of 666, tell me what would be the effective permission with a umask of 022?
666 - 022 ?
640 - 022 ?

None. It would be 640 & ~022
 
Old 12-07-2005, 11:43 PM   #9
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Quote:
Originally Posted by primo
Man, see what the manpage says. It illustrates the point perfectly. It says "files normally created". See the creat(2) manpage and the open(2) manpage. If you specify 640 instead of 666, tell me what would be the effective permission with a umask of 022?
666 - 022 ?
640 - 022 ?

None. It would be 640 & ~022
Sorry my mistake I thought we were talking about normally created files.

Just out of curiosity how are you specifying creating a file with 640 instead of 666 without using umask?
 
Old 12-08-2005, 12:41 PM   #10
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by Blinker_Fluid
Sorry my mistake I thought we were talking about normally created files.

Just out of curiosity how are you specifying creating a file with 640 instead of 666 without using umask?
Code:
foobar()
{
   int fd;
   fd = creat("foobar", 0640);
   /* ... */
}
Code:
foobar()
{
   int fd;
   fd = open("foobar", O_RDWR | O_CREAT, 0640);
   /* ... */
}
mkfifo(2), mknod(2), mkdir(2) and shm_open(3) are similar... they let you specify any permissions (see mode_t).

Last edited by primo; 12-08-2005 at 12:46 PM.
 
Old 12-08-2005, 04:20 PM   #11
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,533

Rep: Reputation: 148Reputation: 148
Moved: This thread is more suitable in Linux-Newbie and has been moved accordingly to help your thread/question get the exposure it deserves. It's a technical thread.
 
Old 12-09-2005, 12:30 PM   #12
osmansm
LQ Newbie
 
Registered: Dec 2005
Location: New York
Distribution: RedHat 9
Posts: 2

Original Poster
Rep: Reputation: 0
thanks to all member for helping me
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
umask trophy Linux - General 1 04-03-2004 01:17 AM
umask=0,0,0 demmylls Linux - General 2 09-15-2003 12:13 PM
Umask robyso Linux - Security 1 07-14-2003 02:33 PM
umask Spaz17 Linux - Newbie 1 07-04-2003 10:12 AM
umask knueven7 Linux - Newbie 8 04-18-2003 07:30 AM


All times are GMT -5. The time now is 07:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration