Display or set the file mode creation mask.
umask [-p] [-S] [mode]
mode (optional): Octal number or symbolic notation.
-p: When no parameters are provided, specifies that the output format should be reusable as input.
-S: Output the creation mask in symbolic notation; otherwise, it is output in octal.
Returns success unless an invalid option or parameter is provided.
The following examples assume a file mode creation mask of 0022.
# Output the creation mask in octal format.
umask -p
# Result:
umask 0022
# Output the creation mask in symbolic notation.
umask -S
# Result:
u=rwx,g=rx,o=rx
Referring to the
DESCRIPTIONsection ofman chmod:
urepresents the current user.grepresents users in the same group as the current user (group users).orepresents other users.arepresents all users.rrepresents read permission (octal 4).wrepresents write permission (octal 2).xrepresents execute permission (octal 1).+adds the specified permissions to the target user(s).-removes the specified permissions from the target user(s).=adds the specified permissions and removes those not mentioned.
The symbolic output u=rwx,g=rx,o=rx translates to octal 0755.
To set the same permissions using an octal mask, umask requires the subtraction 0777 - 0755, which equals 0022 (whereas chmod does not).
Adding, removing, and assigning permissions in symbolic mode:
# Add permission:
# Add write permission for group users.
umask g+w
# Remove permission:
# Remove write and execute permissions for other users.
umask o-wx
# Assign permission:
# Assign all permissions to all users (equivalent to umask u=rwx,g=rwx,o=rwx).
umask a=rwx
# Clear all permissions for other users.
umask o=
Creating directories and files (assuming they don't exist in the current directory):
# Create a file
touch test.sh
# Check permissions; note that execute permission settings do not apply to files by default.
stat test.sh
# Create a directory
mkdir newdir
# Check permissions; execute permission settings do apply to directories.
stat newdir
help command for related help information.chmod is used to change the permissions of existing objects, while umask affects the permissions of newly created objects.TAB key for completion in the terminal.