The Blog

umask

What is umask?

If you are into Linux, you have seen different permissions like read, write, and execute. When you create a directory or a file, you have seen it getting created with default permission. Do you know from where it gets that default value? How does the Linux kernel know that this is the default permission for a directory or a file? Here comes the importance of umask command.

What is umask?

The umask value is subtracted from maximum file permission of a file or directory. This will give the default permission of a file/directory

$ umask

This command will show you the current umask value 

We take the last 3 digit as the value as the first value is used for a security feature. So here, the umask is 002

Let us first look at the octal values of each permission in Linux

For calculating the default permission, we have first look at the full permission of a file is 666 and that of a directory is 777.

Let us change the umask to 0022

For a file, we will have to subtract the umask value from the full permission I.e 666 –022 which is 644

  • The owner will have read and write permission
  • The group will have only read permission
  • Others will have only read permission

Now let us confirm this by creating a new file

We can see the default permission is correct as we calculated

Now, let us calculate the default permission for a directory.

777 –022 = 755

  • The owner will have full permission
  • The group will have read and execute permission
  • Others will also have read and execute permission.

Let us confirm this by creating a directory

We can see that our calculation is correct,

These are the steps to follow when you want to set the default permission of a file or directory

DevOps Gurukul is one of the best training academies which provides  Linux Course In Kochi. We have experienced training professionals who are passionate about grooming the right candidates to start their successful careers. Come learn Best online linux training in Kerala with us and have a bright future!

Leave a Comment

Your email address will not be published.

×

Powered by WhatsApp Chat

× How can I help you?