[Previous] [Contents] [Next]

umask

Get or set the file mode creation mask (POSIX)

Syntax:

umask [-o|-s|mask]

Options:

-o
Display the current mask, in octal.
-s
Display the current mask in symbolic form. This is the default output.
mask
The file mode creation mask can be specified either as an octal number or as a symbolic representation.

If the mask is specified in octal form, it replaces the current file mode creation mask. Every bit that is set describes a mode bit that won't be allowed in the file mode of created files. In other words, it says: "mask this bit off."

The symbolic form of the mask is an expression that modifies or replaces the current file mode creation mask. The form of the symbolic mask is similar to that of the mode operand for the chmod utility:

Where:
a
user, group, and other access
u
user access
g
group access
o
other access
+
add these permissions to the current mask
-
remove these permissions from the current mask
=
replace the current mask with these permissions
r
read permission
w
write permission
x
execute permission
Once the symbolic mask expression has been applied to the current file mode creation mask, any occurrence of [r,w, x] describes a mode bit that will be allowed in the file mode of created files. The absence of a symbol means that permission is not allowed and is masked "off."

Description:

The umask utility sets the file mode creation mask of the invoking process to the value specified by the mask operand. The file mode creation mask affects the initial value of the file permission bits of subsequently created files when no mode is specified.

When files are created without specifying the permission mode bits, the filesystem assigns default permissions of 0777 (rwxrwxrwx) to directories and executable files, thereby giving read, write, and execute privileges for user, group, and others. For files that are not executable, permissions of 0666 (rw-rw-rw-) are assigned. The umask utility is used to adjust these defaults.

The file mode creation mask is inherited by any children of the current process.

Either of the display forms (-o or -s) can be used as the mask operand to a subsequent invocation of the umask utility.

As in the chmod utility, the use of the octal number form of mask values is deprecated.

Examples:

  1. Set mask to allow read, write, and execute, for user, group, and others:
        $ umask a=rwx
        

    Display the current file creation mode mask in symbolic form:

        $ umask -s
        u=rwx, g=rwx, o=rwx
        

    Display the current file creation mode mask in octal:

        $ umask -o
        00
        
  2. Specify that no permissions for group and others be allowed; set the mask to allow only read and write for user only:
        $ umask u=rw
        

    Display the current file creation mode mask in symbolic form:

        $ umask
        u=rw,g=,o=
        

    Display the current file creation mode mask in octal:

        $ umask -o
        0177
        
  3. Add read permissions for group and others:
        $ umask go+r
        

    Display the current file creation mode mask in symbolic form:

        $ umask
        u=rw,g=r,o=r
        

    Display the current file creation mode mask in octal:

        $ umask -o
        0133
        

Exit status:

0
The file mode creation mask was successfully changed, or no mask operand was supplied.
>0
An error occurred.

Errors:

If any error occurs, the value of the process's file mode creation mask is left unmodified.

See also:

chmod


[Previous] [Contents] [Next]