0

How can I change leading zero in umask 0022? Can it be changed?

I searched the usual methods for information and my local system was of little help.

$ man umask  
No manual entry for umask  

$ umask --help
bash: umask: --: invalid option
umask: usage: umask [-p] [-S] [mode]

I found an online umask man page with the following:

umask [-p] [-S] [mode]

mode ... File creation mask
-S ........ Print the mask in symbolic format
-p ........ Output in a form that can be reused as input

Based on this, I tried a few basic umask commands:

$ umask
0022

$ umask -p
umask 0022

$ umask -S
u=rwx,g=rx,o=rx

I was surprised to find that I could not run umask with sudo

$ sudo umask  
[sudo] password :  
sudo: umask: command not found  

I changed the regular umask as follows:

$ umask 021
$ umask
0021

$ umask 0022
$ umask
0022  

Finally, I hit an error while trying to change the leading zero

$ umask 1022
-sh: umask: 1022: octal number out of range  

So, back to my original question, how does one change the leading zero (0)? Is it for the super user (root)? Can it be updated, and if so, to what?

I reviewed a similar question how-is-umask-calculated-in-linux and found:

I don't know that you would unmask the first bit with umask, but technically you could ...

and

I don't believe you can actually set the umask to allow you to enable any of these extra bits by default

So, these uncertain and contradictory statements do not answer this question.

  • 2
    There is (most likely) no manual page for umask on your system because it has no umask binary; only a shell built-in. Search for umask in the manual page for your shell. – user4556274 Mar 24 '17 at 15:28
1

In languages like C or Perl, a leading zero signifies an octal number, and since file permission bits are customarily represented in octal, the zero has to be used in those languages so that the number isn't taken as decimal.

Shell utilities always interpret numeric permissions as octal, so the a zero has no other meaning than padding or making the number look like a C-style octal constant.

Only the lowest 3 octal digits have a meaning in an umask, so the extra zero in something like 0022 seems a bit redundant, unless one wants to pad all numeric permissions to the same length, and leave the leading zero to signify octal.

(POSIX somewhat confusingly says that umask() only uses the permission bits, but at same time, the meaning of the other bits is implementation-defined.)

  • I thought this might be the case. So, it's not something to change, correct? – MikeD Mar 24 '17 at 15:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.