[Previous] [Contents] [Index] [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
Set the file mode creation mask to mask, which you can specify either as an octal number or as a symbolic representation.

If you specify the mask in octal form, it replaces the current file mode creation mask. Every bit that's 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:

[[augo] [+|-|=] [rwx]] [,symbolic_mask]
     

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 is allowed in the file mode of created files. The absence of a symbol means that permission isn't 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 aren't 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.

You can use either of the display forms (-o or -s) as the mask operand to a subsequent invocation of umask.

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

The shell has a builtin umask command; see ksh. To make sure you use the executable, specify the full path.

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. The process's file mode creation mask isn't changed.

See also:

chmod, ksh

Working with Files in the Neutrino User's Guide


[Previous] [Contents] [Index] [Next]