Why is umask a $perms AND NOT $mask and not simply $perms AND $mask instead?

In other words why is there a NOT in there; why doesn't wasn't it implemented as an and mask?

As an example, 666 and 700, to give 600?

2 Answers 2


The key is that the umask ("user mask") is intended to keep processes from creating files with permission bits they're not supposed to use. If you look at it from that perspective, the concept of a umask may make more sense; in particular, the common umask of 022 prevents processes from creating files that are writable by group or world, which is usually what you want.

  • This misses the point of the question. Why is it 022 and not 0755? Commented Jul 3, 2011 at 0:46
  • 2
    No, he nailed it. You want to clear permissions bits, not set them.
    – Jodie C
    Commented Jul 3, 2011 at 1:30
  • Jodie, I think you missed what the OP is demonstrating in his example. He is asking why the mask isn't a representation of what a process is allowed to set (i.e. an 0755 mask would mean that, at most, a process could set group/world read and execute). It's really a question of a design decision made 50 years ago.
    – Kyle Smith
    Commented Jul 3, 2011 at 3:26
  • 1
    I think I see, therefore the way it works was entirely a conceptual decision - to mark permissions that aren't allowed rather than mark permissions that are allowed. I always considered it confusing and the wrong way around. Commented Jul 3, 2011 at 9:31
  • 1
    Unix is not yet 50 years old.
    – JdeBP
    Commented Jul 4, 2011 at 13:06

The input value is octal which may require a leading 0 to be parsed correctly. As the owner mask is almost always 0 the mask can be entered with three digits. As an AND mask, it would need to be entered as 0755 or 0750.

Defining it as an AND NOT operation makes it safer if characters are missed in the mask. If umask was and AND operation umask 5 would allow only limited world access and umask 0 would be even worse. umasq 75 parsed as a decimal value would be be effectively umask 113 which would not allow read acces.

EDIT: From another perspective, the mask is a list of the bits you want masked off. Therefore you want masks like 026 rather than 0751. Internal representation may well be 07751 or what ever is appropriate for ANDing. If not, the conversion is relatively trivial, and in the grand scheme of things the mask doesn't get applied that often.

  • How is this any different than umask(22)? (bash's umask assumes the number is octal if it starts with a digit) Commented Jul 3, 2011 at 4:12
  • @Ignacio A decimal umask(22)`` is treated as umask 026`leaves the owner with full access to the file and is roughly what was intended.
    – BillThor
    Commented Jul 4, 2011 at 3:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .