Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Nov 1997 14:31:46 +1030
From:      Greg Lehey <grog@lemis.com>
To:        "Greg...-*smile*-" <greg@oz.plymouth.edu>
Cc:        questions@FreeBSD.ORG
Subject:   Re: umask command
Message-ID:  <19971104143146.37774@lemis.com>
In-Reply-To: <9711040300.AA05818@oz.plymouth.edu>; from Greg...-*smile*- on Mon, Nov 03, 1997 at 10:00:41PM -0500
References:  <9711040300.AA05818@oz.plymouth.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 03, 1997 at 10:00:41PM -0500, Greg...-*smile*- wrote:
> can someone please explain the umask command to me....
> I found it in my .login

>From the upcoming new edition of "The Complete FreeBSD"

Permissions for new files

None  of this tells us what the permissions for new files are going to be.  The
wrong choice could be disastrous.  For example,  if  files  were  automatically
created  with  the permissions rwxrwxrwx, anybody could access them in any way.
On the other hand, creating them with r-------- could result in a lot  of  work
setting them to what you really want them to be.  UNIX solves this problem with
a thing called umask  (User  mask).   This  is  a  default  non-permission:  it
specifies which permission bits not to allow.

As if this weren't confusing enough, it's specified in the octal number system,
in which the valid digits are 0 to 7.  Each octal digit represents 3 bits.   By
contrast, the more common hexadecimal system uses 16 digits, 0 to 9 and a to f.
The original versions of UNIX ran on  machines  which  used  the  octal  number
system,  and  since  the permissions come in threes, it made sense to leave the
umask value in octal.

An example: by default, you want to create files which anybody  can  read,  but
only  you can write.  You set the mask to 022.   This corresponds to the binary
bit pattern 000010010.  The permissions are allowed where the corresponding bit
is 0:

rwxrwxrwx      Possible permissions
000010010      umask
rwxr-xr-x      resultant permissions

By  default,  files  are  created  without  the x bits, whereas directories are
created with the allowed x bits, so with this umask, a file  would  be  created
with the permissions rw-r--r--.

umask is a shell command.  To set it, just enter:

$ umask 022

It's preferable to set this in your shell initialization file--see page 146 for
further details.

----
Greg



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19971104143146.37774>