举例实现理解 umask 000 on Linux

  • umask

From wikipedia, umask is a command that determines the settings of a mask that controls file permissions are set for newly created files. It may also affect how the file permissions are changed explicitly. umask is also a function that sets the mask, or it may refer to the mask itself, which if formally known as the file mode creation mask. The mask is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files. The bits in the mask may be changed by invoking the umask command.

mask:

From wikipedia, a mask or bitmask is data that is used for bitwise operations, paricularly in a bit field.

Using a mask, multiple bits in a byte, nibble, word etc. can be set either on, off or inverted from on to off in a single bitwise operation.

bitwise operations

From wikipedia, a bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast and simple action, directly supported by the processor, and is used to manipulate values for comparisons and calculations.

要理解umask,需要先理解:

  1. 用户掩码

    所谓用户掩码就是umask,which also known as user mask, user file creation mask.

    umask is a security command and a function in POSIX environments that sets the default privileges that a file get when it’s created.

  2. 文件权限

  • 遮罩掉

Chris McCandless from Into the Wild ,在阿拉斯加的房车横梁上有一句话,我印象深刻,大意是:Call everything by its right name.

Robert J.Shiller who written the book 《非理性繁荣》在公开课上有一个角度叫Thinking Frame,同样事物表述角度不同,则理解不同。

遮罩掉这个词更能精准表达umask的底层逻辑,umask对权限的控制在于“去除”。在原有权限的基础上去掉umask表示的权限,就像一个过滤器,权限是屋里的三个孩子(读、写、执行),umask如果是执行,就像是一个老师,拿这“执行”的画像守在门口,三个孩子往外跑,umask这个老师专门把“执行”拦下来。

umask 000就是老师谁也不限制,三个孩子可以尽情的玩耍。

  • Reference

  1. Linux中umask深入理解
  2. What is “umask” and how does it work?
  3. umask,补码,ASCII码:稍微深入考虑一点

你可能感兴趣的:(#,Linux,umask,000)