Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(1)

csh(1)

ksh(1)

sh-posix(1)

sh(1)

chmod(2)

creat(2)

umask(2)

umask(1)

NAME

umask − get or set the file mode creation mask

SYNOPSIS

Get Mask:

umask [-S]

Set Mask:

umask [mask]

DESCRIPTION

umask is a built-in shell command (executed within the shell process) that can be used to print the current file mode creation mask value or to set a new one. 

When a new file is created, each bit in the file mode creation mask that is set causes the corresponding permission bit in the the file mode to be cleared (disabled); hence the term mask. Conversely, bits that are cleared in the mask allow the corresponding file mode bits to be enabled in newly created files. 

Getting Current Mask Value

To print the current file mode creation mask value, use one of the commands:

umask Print the octal value of the current file mode creation mask. 

umask -S Print the current file mode creation mask value using a symbolic format that resembles:

u=rwx,g=rwx,o=rwx

where zero, one, two, or three of the letters r, w, and x are printed for each category: u (user (or owner)), g (group), and o (other), depending on the current mask setting.  Each r, w, or x in the output indicates that the corresponding permissions are allowed in newly created files. 

Both command-line forms produce output that is a valid value for use as the mask argument in a subsequent umask command when setting a new mask value. 

Note that the -S option is implemented only in the Korn shell (see ksh(1)) and in the POSIX shell (see sh-posix(1)). Other shells such as Bourne shell (see sh-bourne(1)) and C shell (see csh(1)) do not support the symbolic output form.

Setting A New Mask Value

To set a new file mode creation mask value for the current shell execution environment, use the command:

umask mask

where mask can be a symbolic value or a non-negative octal integer (obsolescent).  The resulting interpreted mask affects the initial value of the file permission bits for subsequently created files. 

Symbolic mask Value:
The umask command built into the POSIX and Korn shells accepts symbolic mask values (as well as the obsolescent octal form).  Symbolic mask values are constructed in the same manner as when using the chmod command (see chmod(1)) by concatenating comma-separated strings of the form:

who operator permissions

constructed as follows:

who One of the characters or character combinations u, g, o, ug, uo, go, ugo, or a (short form for ugo).  If who is not specified, the operator and permissions apply to all categories.  If two or more who categories have the same mask value, they can be placed together by using ug, uo, go, ugo, or a as appropriate. 

If who is omitted, operator and permissions apply to all categories (same as a or ugo). 

operator One of the characters +, -, or =.  An operator is required for each who. Multiple operations can be performed on a given who in a complete mask argument, such as when permissions are deleted from all or some categories then new permissions are added by another mask substring (see EXAMPLES below). 

If no permissions are specified for a given operator, no change is made to the current file creation mode mask. If who is not specified, the operation applies to all categories (u, g, and o). 

operators are interpreted as follows:

+ Clear the file mode bits represented by the accompanying who and permissions values in the mask, thus enabling corresponding permissions in newly created files. 

- Set the file mode bits represented by the specified who and permissions values in the mask, thus denying corresponding permissions in newly created files. 

= Clear the file mode bits specified by the corresponding who and permissions values and set all others. 

permissions
One of the characters or character combinations r, w, x, rx, wx, rw, or rwx, specifying read, write, and/or execute (search) permission for the corresponding who and operator.

If permissions is not specified, no change is made to the existing file creation mode mask for the corresponding who.

Octal mask Value (obsolescent):
The umask command built into the POSIX, Korn, C, and Bourne shells accepts a non-negative integer value for mask. For an octal integer mask operand, the file mode bits are set absolutely. 

If the user file-creation mode mask value is specified as three octal digits, they refer to read/write/execute permissions for owner, group, and others, respectively (see chmod(2) and umask(2)). The value of each specified digit is subtracted from the corresponding “digit” specified by the system for the creation of a file (see creat(2)). For example, the command umask 022 removes group and others write permission (files normally created with mode 777 become mode 755; files created with mode 666 become mode 644). 

The following table gives the octal integers and the corresponding mode-bits:

User Group Other
Symbolic Octal Mode bit Symbolic Octal Mode bit Symbolic Octal Mode bit
u+r 0400 S_IRUSR g+r 0040 S_IRGRP o+r 0004 S_IROTH
u+w 0200 S_IWUSR g+w 0020 S_IWGRP o+w 0002 S_IWOTH
u+x 0100 S_IXUSR g+x 0010 S_IXGRP o+x 0001 S_IXOTH

If mask is omitted, the current value of the mask is printed in octal.  The first digit, a zero, specifies that the output is expressed in octal.  umask writes a message to standard output that can be later used as a umask mask operand.  The use of an operand obtained in this way is not obsolescent, even if it is an octal number. 

If a mask operand is specified, there is no output written to standard output. 

umask is recognized and executed by the shell. 

Note that the file creation mode mask does not affect the set-user- ID, set-group- ID, or “sticky” bits. 

Since umask affects the current shell execution environment, it is generally provided as a shell regular built-in.  Moreover, different shells provide different implementations of umask as a built-in.  Features of umask as described here may not be supported by all the shells.  Refer to the manual entry for specific shells for differences. 

If umask is called in a subshell or separate utility execution environment such as one of the following:

(umask 002)
nohup umask ... 
find . -exec umask ... 

it does not affect the file mode creation mask of the caller’s environment. 

RETURN VALUE

umask exits with one of the following values:

 0 The file mode creation mask was successfully changed or no mask operand was supplied. 

>0 An error occurred. 

EXAMPLES

Symbolic-Mode:

Set the umask value to produce read, write, and execute permissions for the file’s owner and read-only permission for all others (-rwxr--r--) on newly created files:

umask u=rwx,g=r,o=r

Set the umask value to produce read, and write permissions for the file’s owner, read-only for others users in the same group, and no access to others (-rw-r-----):

umask a-rwx,u+rw,g+r

Octal-Mode:

Set the umask value to deny read, write, or execute permissions to everyone (----------):

umask 0777

SEE ALSO

chmod(1), csh(1), ksh(1), sh-posix(1), sh(1), chmod(2), creat(2), umask(2). 

STANDARDS CONFORMANCE

umask: SVID2, XPG2, XPG3, POSIX.2

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026