|HP-UX Reference > U
umask(1)HP-UX 11i Version 3: February 2007
umask — set or display the file mode creation mask
The umask command sets the value of the file mode creation mask or displays the current one. The mask affects the initial value of the file mode (permission) bits for subsequently created files.
Setting the File Mode Creation Mask
The umask mask command sets a new file mode creation mask for the current shell execution environment. mask can be a symbolic or numeric (obsolescent) value.
A symbolic mask provides a flexible way of modifying the mask permission bits individually or as a group. A numeric mask specifies all the permission bits at one time.
When a mask is specified, no output is written to standard output.
Symbolic Mask Value
A symbolic mask replaces or modifies the current file mode creation mask. It is specified as a comma-separated list of operations in the following format. Whitespace is not permitted.
The fields can have the following values:
If one or two of the fields are omitted, the following table applies:
Numeric Mask Value (Obsolescent)
A numeric mask replaces the current file mode creation mask. It is specified as an unsigned octal integer, constructed from the logical OR (sum) of the following mode bits (leading zeros can be omitted):
0400 ( a=rwx,u-r) Read by owner 0200 ( a=rwx,u-w) Write by owner 0100 ( a=rwx,u-x) Execute (search in directory) by owner 0040 ( a=rwx,g-r) Read by group 0020 ( a=rwx,g-w) Write by group 0010 ( a=rwx,g-x) Execute/search by group 0004 ( a=rwx,o-r) Read by others 0002 ( a=rwx,o-w) Write by others 0001 ( a=rwx,o-x) Execute/search by others
Displaying the Current Mask Value
To display the current file mode creation mask value, use one of the commands:
Both forms produce output that can be used as the mask argument to set the mask in a subsequent umask command.
When a new file is created (see creat(2)), each bit that is set in the file mode creation mask causes the corresponding permission bit in the the file mode to be cleared (disabled). Conversely, bits that are clear in the mask allow the corresponding file mode bits to be enabled in newly created files.
For example, the mask u=rwx,g=rx,o=rx (octal 022) disables group and other write permissions. As a result, files normally created with a file mode shown by the ls -l command as -rwxrwxrwx (octal 777) become mode -rwxr-xr-x (octal 755); while files created with file mode -rw-rw-rw- (octal 666) become mode -rw-r--r-- (octal 644).
Note that the file creation mode mask does not affect the set-user-id, set-group-id, or "sticky" bits.
The file creation mode mask is also used by the chmod command (see chmod(1)).
Since umask affects the current shell execution environment, it is generally provided as a shell regular built-in (see DEPENDENCIES).
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 calling environment.
The default mask is u=rwx,g=rwx,o=rwx (octal 000).
umask exits with one of the following values:
In these examples, each line show an alternate way of accomplishing the same task.
Set the umask value to produce read and write permissions for the file's owner and read permissions for all others (ls -l displays -rw-r--r-- on newly created files):
umask u=rwx,g=rx,o=rx symbolic mode umask a=rx,u+w symbolic mode umask 022 numeric mode
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 symbolic mode umask u=rw,g=r,o= symbolic mode umask ,u+rw,g+r symbolic mode umask 137 numeric mode
Set the umask value to deny read, write, and execute permissions to everyone (----------):
umask a= symbolic mode umask 777 numeric mode
Add the write permission to the current mask for everyone (there is no equivalent numeric mode):
umask a+w symbolic mode
If you set a mask that prevents read or write access for the user (owner), many programs, such as editors, that create temporary files will fail because they cannot access the file data.
The umask command is implemented both as a separate executable file (/usr/bin/umask) and as built-in shell commands.
POSIX Shell and Separate File
All features are supported (see sh-posix(1)). The numeric mask display uses a minimum of two digits.
The -S option is not supported in the Korn shell built-in command (see ksh(1)). The numeric mask display uses a minimum of two digits.
The -S option and symbolic mask values are not supported in the C shell built-in command (see csh(1)). The numeric mask display uses a minimum of one digit.