×


Umask Command in Linux - Overview

UMASK in a Linux system also known as User Mask is the default permission of a file or directory when they are created in your Linux machine. In a more clearer form, Umask, or the user file-creation mode, is a Linux command that is used to assign the default file permission sets for newly created folders and files. The term mask references the grouping of the permission bits, each of which defines how its corresponding permission is set for newly created files. The bits in the mask may be changed by invoking the umask command. Most Linux distros have a default value of UMASK as 022.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.

In this context, we shall look into how to use UMASK.


How to Calculate the value of UMASK ?

The minimum and maximum values of umask for a directory are 000 and 777 respectively. The minimum and maximum values of umask for a file are 000 and 666 respectively. The following table describes some of the common values:

  • 0 Read, Write & Execute
  • 1 Read & Write
  • 2 Read & Execute
  • 3 Read Only
  • 4 Write & Execute
  • 5 Write Only
  • 6 Execute Only
  • 7 No Permissions


To get a better understanding of how to use UMASK in Linux, let’s analyze the following example:

If the value of umask is 077, it means:

  • 0 – the Owner has Read, Write and Execute permission
  • 7 – the Group has no Permissions
  • 7 – Others have no Permissions


$ umask 077
$ mkdir new-folder
$ touch new-file
$ ls -ld new-folder new-file

   

How to Get the current umask value ?

You can get the current value of umask by simply running the command:

$ umask


Alternative way to set the umask value

Besides the method of using numeric value for umask, you can configure the umask by alphabetic value as:

  • r – Read
  • w – Write
  • x – Execute
  • u – User ownership
  • g – Group ownership
  • o – other ownership


For instance:

$ umask u=rw
$ mkdir test-folder
$ touch file-test
$ ls -ld test-folder file-test


[Need help in fixing Linux System Firewall issues? We can help you. ]


Conclusion

This article covers how to use UMASK in the Linux system. On Linux operating systems, new files are created with a default set of permissions. Specifically, a new file's permissions may be restricted in a specific way by applying a permissions "mask" called the umask. The umask command is used to set this mask, or to show you its current value.