Re: umask question
From: Robert Newson (ReapNewsB_at_bullet3.fsnet.oc.ku)
Date: Fri, 22 Jul 2005 22:32:53 GMT
Shel Sherman wrote:
> Thanks for the reply. You verified my suspicion that the leftmost zero
> implied octal. However, here is the rest of the puzzle. I ran several values
> of umask, created empty files using "touch" called foo1, foo2, etc. and
> looked at the resulting permissions via ls -l for each value of umask. The
> results are tabulated below. Some results were as expected. Others leave me
> scratching my head.
> UMASK RESULT OCTAL EQUIVALENT EXPECTED
> 0022 rwxr_xr_x 755 yes
> 0777 --------- 000 yes
> 0321 r__r__rw_ 446 NO
> 0210 r__rw_rw_ 466 NO
> 0111 rw_rw_rw_ 666 yes
> 0123 rw_r__r__ 644 NO
> Note that three of the six masks used did not yield the expected results.
> So I remain.....Still confused.
If you check the results that failed to arrive as expected, you should spot
a pattern: the 'x' bit is always masked to be off.
This is probably as a security feature: the eXecute bit is being forced to
be off on a regular file so that you have to explicitly set it - so that
it's less likely that you'll accidently run something you shouldn't, or
attempt to run something that isn't a program.
Note that compilers (eg gcc) will [usually] automatically set the x bits as
per the umask - as the resultant file *is* a program.
Similarly, when you create a directory (with mkdir), it will use the full
umask - which means if you've disabled the x bit (eXecute = search for
directories) you won't be able to access any file within that directory
(including creating any even if you've got Write perms on the directory).