What is umask?

umask? What?

What is umask command use for in linux/unix system?

umask is uses to set the default file or directory permission when a user create a new file or directory. By default, when a user created new file/directory, the default permission is 644/755 or umask 022, that is the default umask configure in the your unix/linux system.

umask calculation

How does the umask calculation works? Simple, subtract the default value of file value (666) and directory value (777) to the permission mode you wanted. In an example, I would like a new files/directory create with owner (Read/Write/Execute), group (read), others (read), the umask value would be umask 022.

If you want the permit an unix user created the file with default permission 600, set the umask to 066 in the default shell config file.

Test with umask

Setting the umask to 066 and see what will happen.


shell> umask 066
shell> mkdir foo
shell> ls -dl foo

drwx--x--x  2 takizo  takizo    68B May 21 08:57 foo

the directory is created with permission mod 711


shell> touch bar
shell> ls -l bar

-rw-------  1 takizo  takizo     0B May 21 09:00 bar

the file is create with permission mod 600