Umask command in Linux with examples
Last Updated :
19 Mar, 2025
The umask command in Linux is used to set default permissions for files or directories the user creates.
How does the umask command work?
- The umask command specifies the permissions that the user does not want to be given out to the newly created file or directory.
- umask works by doing a Bitwise AND with the bitwise complement(where the bits are inverted, i.e. 1 becomes 0 and 0 becomes 1) of the umask.
- The bits which are set in the umask value, refer to the permissions, which are not assigned by default, as these values are subtracted from the maximum permission for files/directories.
How to calculate umask value?
Syntax:
$umask
[The above command will give the following output]

umask command in Linux without parameters (output)
pratyay@pratyay-ROG-Strix-G531GT:~/Study/Linux/CommandTrials/umask$ umask
0002
- Here, the first digit, 0 is called the sticky bit, it is a special security feature.
- The next three digits represent the octal values of the umask for a file or directory.
For a better understanding of umask working, we need to understand octal mode security settings. The three rwx permissions (Read-Write-Execute) values are converted into three-bit binary values and represented by a single octal value as shown in the following table:
Permissions |
Octal Value |
Binary Value |
Description |
— |
0 |
000 |
No permission |
–x |
1 |
001 |
only permission to execute |
-w- |
2 |
010 |
only permission to write |
-wx |
3 |
011 |
permission to write and execute |
r– |
4 |
100 |
only permission to read |
r-x |
5 |
101 |
permission to read and execute |
rw- |
6 |
110 |
permission to read and write |
rwx |
7 |
111 |
permission to do all three, i.e. read, write and execute |
Simplification:
Let’s understand the above table with an example: Let’s explain the previous output we got using umask, 0002
- For a better understanding of the above table, it might seem confusing at first, but it’s pretty simple, all you have to remember is the three modes, rwx (read-write-execute).
- the bit for the respective mode, i.e. in 3-bit number, the first bit(leftmost) is for read, then write and execute respectively. In the above example, 0002 is outputted by the umask command, we will be not worrying about the first 0 as of now. the next three digits are 0 0 2.
- Each digit here is for different classes of users, there are a total of 3 classes of users in Linux,
- The owner
- group members
- everyone else
- The above output (0002) means that the umask is restricting write permissions for ‘others’. Since umask subtracts from the default permissions:
- For a file (default:
666
), the umask 0002
results in 664
(rw-rw-r--
), meaning others can only read the file.
- For a directory (default:
777
), the umask 0002
results in 775
(rwxrwxr-x
), meaning others can only read & execute, but not write.”
- The umask
0002
ensures that while owner and group can read & write, others can only read (for files) or read & execute (for directories)
How to set and update the default umask value?
We can set and update the default umask value using the command umask followed by a parameter, which should be an integer ranging from 000-777. The syntax for updating the umask value is the same as setting the umask value.
Setting the umask value:
We can use the umask command to set the default permissions with which the files/directories will be created.
Syntax
$umask 543

umask command in Linux terminal (Setting default umask value)
How to calculate umask values for files and directories?
Here, when we execute the command, the values are not directly allocated as 5 for the owner, 4 for the group members and 3 for the others, but the value we pass as an argument is subtracted from the max/full permission set. There are two full permission sets:
- File -> The full permission set for a file is 666 (read/write permission for all)
- Directory -> The full permission set for a directory is 777 (read/write/execute)
Note: The files cannot be given execution permissions by default as it can cause a security concern, and Linux systems are pretty much known for their amazing security, so that wouldn’t be good.
So, once we have set the umask value to 543, let’s see what happens when we make a directory(7-7-7) and a file(6-6-6)
Making a directory:
- When we make a new directory, the permissions will be calculated as (full permissions for directory) – (umask value) i.e. 777 – 543 = 234
- 234, can be clarified more as:
- 2 for the owner, that is 010 in binary, so write permissions for the owner.
- 3 for the group members, that is 011 in binary, so write and execute permissions for the group members.
- 4 for everyone else, that is 100 in binary, so only read permission for everyone else.

Making a directory with custom set umask
- The output shows the following: d-w–wxr–, which is a bit confusing, but when we simplify it, it can be seen as d -w- -wx r–, d here stands for directory and the latter 3 are the permissions for the respective users as we discussed in the previous point.
Making a file:
- When we make a new directory, the permission will be given out similarly but with a slight change as follows: (full permissions for file) – (umask value) i.e. 666-543 = 123
- Linux does not provide execute permissions by default, even if it is specified in the umask.
- 123 can be clarified more as:
- 1 for the owner, that is 001 in binary, so execute permission should be given to the owner, but Linux doesn’t give execute permissionMaking a directory:s by default, so, the value is promoted by one and we get 010, and write permission will be granted to the owner.
- 2 for the group members, that is 010 in binary, so write permissions for the group members.
- 3 for everyone else, that is 011 in binary, so write and execute permission for everyone else, but again execute permission cannot be provided, so the value will be promoted one more time, and we will get 100, so read permission will be granted to everyone else.

Making a file using custom set umask
- The output shows, –w–w-r– which can be simplified as – -w- -w- r–, that is write for the owner, write for the group, and read for everyone else.
- Now when we will try to open this file as the owner, we will get access denied, as the owner of the file only has access to write to it.

Trying to open the file without access
- So in order to open the file, we would either have to be the admin or be other than owner and group members.
- Opening file as Admin:

Opening file as admin
- You can also use symbolic notations with umask. Below in “umask u-w” command ‘u’ stands for user and ‘-‘ is used for remove permission and ‘w’ stands for write permission.
- Create File named newDir and check permissions.
- In given figure it shows that permission for newDir is “dr-x-wx—” and user’s write permission has been removed.
- If you use ‘+’ symbol instead of ‘-‘ then it will give corrosponding permission to the user. you can also use ‘r’ which is used for read permission. ie. umask u+rw
- Now, Give write permission to user and check it’s permission by creating an directory.
So, in this way, it is possible to use umask command in order to set default permissions for files and directories. It should be noted that the default permissions for files and directories are different as files do not provide the option to execute by default.
What is the difference between chmod and umask?
- The umask command can be only used on new files i.e. while creating new files, any files created prior to using the umask command will have no effect.
- The chmod command must be used on files that are already present, it is used to change the access permissions of files that have been created earlier.
Thus, we need umask command in order to set the default access permissions for files and directories which will be created in the future, and we need the chmod command in order to change the access permissions for files that have been already created and are present in the system.
Similar Reads
uname command in Linux with Examples
Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th
4 min read
users command in Linux with Examples
users command in Linux system is used to show the user names of users currently logged in to the current host. It will display who is currently logged in according to FILE. If the FILE is not specified, use "/var/run/utmp". "/var/log/wtmp" as FILE is common. Syntaxusers [OPTION]... [FILE]where, OPT
2 min read
mailq Command in Linux with Examples
mailq i.e. "mail-queue", this command in Linux prints the mail queue i.e. the list of messages that are there in the mail queue. You should have a mail-server setup on your Linux machine, to use this command, there are ways i.e MTA's(Mail Transfer agent) you can use like sendmail which uses the serv
3 min read
lsusb command in Linux with Examples
The 'lsusb' command in Linux is a useful utility for displaying information about USB buses and the devices connected to them. It provides a detailed view of the USB hardware connected to your system, including details such as speed, bus number, device class, and type. This command is particularly v
2 min read
Linux make Command with Examples
The make command for Linux is a very useful utility in the automation of software development and performing tasks in a Linux environment. It simply reads a special file, which is called a Makefile and this file describes how one's program is compiled and linked with another file or another program
6 min read
w command in Linux with Examples
The 'w' command in Linux gives us important information about who is currently using the computer, how much the computer is being used, and what programs are running. It's a handy tool for people who take care of computer systems, as it helps them keep an eye on what users are doing, how much of the
3 min read
uniq Command in Linux with Examples
The uniq command in Linux is a command-line utility that reports or filters out the repeated lines in a file. In simple words, uniq is the tool that helps to detect the adjacent duplicate lines and also deletes the duplicate lines. uniq filters out the adjacent matching lines from the input file(tha
7 min read
whatis Command in Linux with Examples
whatis command in Linux is used to get a one-line manual page description. In Linux, each manual page has some sort of description within it. So, this command search for the manual pages names and show the manual page description of the specified filename or argument. Syntax of the `whatis` command
5 min read
more command in Linux with Examples
The 'more' command in Linux is a useful tool for viewing text files in the command prompt, particularly when dealing with large files like log files. It displays the content one screen at a time, allowing users to scroll through the text easily. This command is especially handy for reviewing long ou
4 min read
read command in Linux with Examples
read command in the Linux system is used to read from a file descriptor. This command reads up the total number of bytes from the specified file descriptor into the buffer. If the number or count is zero, this command may detect errors. But on success, it returns the number of bytes read. Zero indic
3 min read