Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In simple form the what is the difference between "mask" and "mode"? From what I understand is if a file has a mask of 0755 the mode of the file would be 7022 correct? It is basically inverted numbers?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Files have modes, on creation time the mask will determine the mode, based on the requested mode. A mask works like a stencil and can best be illustrated using the binary representation.

An umask of 0002 (common octal integer format) is represented as

000 000 000 010

in binary form, or

--- --- --- -w-

in symbolic form.

Let's say a file is to be created by the user, the mode is 0777 by default (for executables), but the mask will be "substracted" in a manner of speaking. This results in the w bit to be removed.

--- rwx rwx rwx  (mode)
--- --- --- -w-  (mask)
_______________ -
--- rwx rwx r-x  ==  000 111 111 101  ==  0775

For regular files (non-executables), the requested mode is without the x (executable) bit, i.e. 0666, so the mask will then result in:

--- rw- rw- rw-  (mode)
--- --- --- -w-  (mask)
_______________ -
--- rw- rw- r--  ==  000 110 110 100  ==  0664

The latter one is common in directory listings (in which the first octet with SUID/SGID bits isn't shown), e.g.:

-rw-rw-r--   2 gert gert      228 Mar 20  2012 .vimrc

Of course, you can always change these modes with for example the chmod command, for which the umask will not be considered in editing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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