[PLUG] umask

Brian Derr bderr at myrealbox.com
Tue Apr 20 17:57:01 UTC 2004


On Sat, Apr 17, 2004 at 08:14:33AM -0700, Evan Heidtmann wrote:
> This is from my umask manpage. (for the C function)
> 
> The  umask  is  used  by  open(2)  to set initial file permissions on a
> newly-created file.  Specifically, permissions in the umask are  turned
> off  from  the  mode  argument  to open(2) (so, for example, the common
> umask default value of 022 results in new files being created with per-
> missions  0666  &  ~022  = 0644 = rw-r--r-- in the usual case where the
> mode is specified as 0666).

The umask just subtracts permissions for newly created files.  For a
normal file the default permissions are 0666 or rw-rw-rw-.  When you add
in a umask of 0022 you get the following:  666 - 022 = 644 or rw-r--r--.
Umasks are really a simple concept, you just have to remember they are
*subtracting* from the default permissions.  666 for a normal file, 777
for a directory.

Here is a little lesson:

brian at brian:~$ umask
0022
brian at brian:~$ umask 000
brian at brian:~$ umask
0000
brian at brian:~$ mkdir f00
brian at brian:~$ ls -ld f00
drwxrwxrwx  2 brian users 48 Apr 20 20:54 f00/
brian at brian:~$ umask 022
brian at brian:~$ mkdir f00b4r
brian at brian:~$ ls -ld f00b4r
drwxr-xr-x  2 brian users 48 Apr 20 20:54 f00b4r/

Brian

-- 
The just man walketh in his integrity:
his children are blessed after him.  -- Proverbs 20:7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.pdxlinux.org/pipermail/plug/attachments/20040420/dca7bbe6/attachment.asc>


More information about the PLUG mailing list