Umask Calculator
How it works
The umask value defines the default permissions when a new file or directory is created.
For files: default permissions (666) - umask
For directories: default permissions (777) - umask
Example: If your umask is 022, then:
Boost Your Website Speed!
If you want your website to run as fast as ours, consider trying Cloudways. Their powerful cloud infrastructure and optimized stack deliver exceptional performance. Free migration!For files: 666 - 022 = 644
(which means the file will be created with rw-r–r–)
For directories: 777 - 022 = 755
(which means the directory will be created with rwxr-xr-x)
But this is not always correct. Here are the mapping table between umask bit and permissions.
Umask Bit | File Permissions (Default 666) | Directory Permissions (Default 777) |
---|---|---|
0 | rw- (read and write) | rwx (read, write, and execute) |
1 | rw- (read and write, no execute) | rw- (read and write) |
2 | r– (read only) | r-x (read and execute) |
3 | r– (read only, no write or execute) | r– (read only) |
4 | -w- (write only) | -wx (write and execute) |
5 | -w- (write only, no read or execute) | -w- (write only) |
6 | — (no permissions) | –x (execute only) |
7 | — (no permissions) | — (no permissions) |
Umask Permission Calculator
File Permissions
Directory Permissions
Using the Umask Command in Linux
The umask command in Linux is used to set default permissions for newly created files and directories.
Here’s how to use it:
1. Check Current Umask Value
To see the current umask value, simply type:
umask
This will display the umask in octal format (e.g., 0022).
2. Set a New Umask Value
To set a new umask value, use the command:
umask [value]
For example, to set the umask to 0022:
umask 0022
This means:
- Owner can read and write (rw-)
- Group can read (r–)
- Others can read (r–)
3. Using Umask in a Shell Session
If you want to make a temporary change for the duration of the current shell session, simply set it as shown above. Once you close the session, it will revert to the default value.
4. Making Umask Changes Permanent
To make umask changes permanent:
-
- Open your shell configuration file (e.g., ~/.bashrc, ~/.bash_profile, or ~/.profile) in a text editor.
- Add the line:
umask 0022
-
- Save the file and reload it using:
source ~/.bashrc
5. Understanding Umask Values
Umask values are typically specified in octal:
- The default permissions for files are 666 (rw-rw-rw-) and for directories are 777 (rwxrwxrwx).
- The umask value is subtracted from these defaults. For example, a umask of 0022 will result in:
- Files: 666 – 022 = 644 (rw-r–r–)
- Directories: 777 – 022 = 755 (rwxr-xr-x)
Example Usage
Setting umask to 007
umask 007
This means:
- Owner can read, write, execute (rwx)
- Group can read, write, execute (rwx)
- Others have no permissions (—)
Creating a Directory
After setting umask 007, any new directory created will have rwxrwx— permissions by default.
Summary
- Use umask to control default permissions for new files and directories.
- You can set it for the current session or make it permanent in configuration files.
- Understanding the octal values helps in determining effective permissions.