umask — Set or return the file mode creation mask

umask [–S] [mode]

Purpose

umask sets the file-creation permission-code mask of the invoking process to the given mode. You can specify the mode in any of the formats recognized by chmod; see chmod — Change the mode of a file or directory for more information.

The file-creation permission-code mask (often called the umask) specifies the restrictions on the permissions for any file created by the process and plays a part in determining how permission bits are changed.

When a program creates a file, it requests that the file have certain permissions. The umask is applied to the requested permissions to determine the actual permissions that the file will have. The actual permissions will be as follows:
  • If a permission bit in the umask is on, the corresponding bit in the actual permissions will be off.
  • If a permission bit in the umask is off, the corresponding bit in the actual permissions will be as the program requested.

Therefore, the umask is used to screen out permissions that a program may request. The umask does not affect other mode values, such as set-user-ID, set-group-ID, and the sticky bit.

If the bit is turned off in the umask, a process can set it on when it creates a file. This can be done using a symbolic representation of the permissions as on the chmod command, or by specifying a numeric umask directly. With the symbolic method, you specify the permissions you want to allow. This is converted into the actual umask value, which conversely represents what will be screened out. If you specify:
umask a=rx
You have explicitly set it so that all users have read and execute access. If you were to look at the mask, it would be 0222. The write bit is set, because write is not allowed. If everyone were permitted rwx access, the umask would be 0000. For example, if a command attempts to create new files with permissions of w for all, and the umask was 0222 as above, the w permissions would not be set.

If you call umask without a mode argument, umask displays the current umask.

Options

–S
Displays the umask in a symbolic form:
u=perms,g=perms,o=perms
giving owner, group and other permissions. Permissions are specified as combinations of the letters r (read), w (write), and x (execute).

Localization

umask uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
See Localization for more information.

Exit Values

Possible exit status values are:
0
Successful completion
1
Failure due to an incorrect command-line argument, or incorrect mode

Portability

POSIX.2, X/Open Portability Guide, UNIX systems.

Related Commands

chmod