The umask
command is used to display or set the permission mask for creating files. The permission mask is a set of bits that determine the default permissions for new files and directories created by a user. By default, the permission mask is set to 022, which means that new files will have permissions of 644 and new directories will have permissions of 755.
Overview
The umask
command can be used to display the current permission mask by running the following command:
umask
This will output the current permission mask in octal format.
To set the permission mask, you can use the following command:
umask [mode]
Where [mode]
is the new permission mask you want to set. The mode can be specified in either octal or symbolic notation.
In octal notation, the mode is a three-digit number that represents the permission bits that should be turned off. For example, to set the permission mask to 027, you would run the following command:
umask 027
This would set the permission mask to turn off the write permission for the group and others.
In symbolic notation, the mode is a string that represents the permission bits that should be turned off. The string consists of one or more of the following characters: u
(user), g
(group), o
(others), a
(all), r
(read), w
(write), and x
(execute). For example, to set the permission mask to 027 using symbolic notation, you would run the following command:
umask u=rwx,g=,o=wx
This would set the permission mask to turn off the write permission for the group and others.
Options
The following options are available for the umask
command:
Option | Description |
---|---|
-S | Display the current permission mask in symbolic notation |
-p | Display the current permission mask in octal notation suitable for use in a shell script |
Troubleshooting tips
- If you are having trouble setting the permission mask using symbolic notation, make sure you are using the correct syntax. The syntax is
who=permissions
, wherewho
is one ofu
,g
,o
, ora
, andpermissions
is a combination ofr
,w
, andx
. - If you are having trouble setting the permission mask using octal notation, make sure you are using the correct octal values. The octal values represent the bits that should be turned off, not the bits that should be turned on.
Notes
- The permission mask is inherited by child processes, so any files or directories created by a process will have the same permissions as the process’s umask.
- The default permission mask of 022 is set in the system-wide
/etc/profile
file. If you want to change the default permission mask for all users, you can modify this file.