umask
Command in Linux
Summary
The umask
command in Linux sets or displays the file mode creation mask, which determines the permissions of newly created files and directories. It's a crucial tool for controlling default permissions.
Introduction
The umask
(user file-creation mode mask) is a shell command that controls the default permissions assigned to newly created files and directories. It's essentially a filter that removes permissions from the default set. The umask
value is subtracted from the default permissions to determine the final permissions. For files, the default is 666 (rw-rw-rw-), and for directories, it's 777 (rwxrwxrwx). The umask
value is usually set in octal format (e.g., 0022).
Use case and Examples
Displaying the Current umask
umask
value. The output will be a number, typically in the range of 0000 to 0777. Setting a New umask
umask
to 0027. This will remove write permissions for group and others and execute permissions for others on newly created files and directories. Creating a File with a Specific umask
umask
to 0022, creating a new file newfile.txt
will result in permissions of 644 (rw-r--r--). This is because the umask
(022) removes write permission for the group and others from the default file permission of 666. Creating a Directory with a Specific umask
umask
to 0022, creating a new directory newdirectory
will result in permissions of 755 (rwxr-xr-x). This is because the umask
(022) removes write permission for the group and others from the default directory permission of 777. Interpreting umask
Values
umask
in symbolic format (e.g., u=rwx,g=rx,o=rx
). This is often easier to understand than the octal representation. Commonly used flags
Flag | Description | Example |
---|---|---|
-S | Displays the umask value in symbolic format (e.g., u=rwx,g=rx,o=rx ). | umask -S |
-p | If supported, outputs a umask command that, when executed, sets the umask to the current value. | umask -p |
octal value | Specifies the new umask value in octal format. | umask 0077 |