Umask or file mode creation mask is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files or directories. The bits in the mask may be changed by invoking the umask command. If the mask has a bit set to "1", it means the corresponding initial file permission will be disabled. A bit set to "0" in the mask means that the corresponding permission will be determined by the program and the system.
The typical default value for umask is 022 (octal). In the usual case when creating a new file, the requested permission mode is 0666 (octal). For a new directory - 0777 (octal). The resulting permission mode will be: R = P & ( ! M ) That is, the resulting permission mode (R) is a result of a logical AND operation between the negation of the mask (M), and the requested permission mode (P). Permissions may be changed later by users and programs using chmod command.
The following table show some examples of how umask impacts resulting permission mode for newly created files and directories.
(requested permissions 666)
(requested permissions 777)
|000||666 (rw-rw-rw-)||777 (rwxrwxrwx)|
|002||664 (rw-rw-r--)||775 (rwxrwxr-x)|
|007||660 (rw-rw----)||770 (rwxrwx---)|
|022||644 (rw-r--r--)||755 (rwxr-xr-x)|
|027||640 (rw-r-----)||750 (rwxr-x---)|
|077||600 (rw-------)||700 (rwx------)|
|277||400 (r--------)||500 (r-x------)|