Categories
Linux Tutorial Series

Linux Tutorial Series – 118 – umask – default permissions

Here is the video version, if you prefer it:

Today let’s talk about default file permissions. We know that we can change file permissions with the chmod command, but where do default permissions come from?

The answer is that default permissions come from the application that produced the file in question. (“What is ‘umask’ and how does it work?,” n.d.)⁠ Then those permissions are modified with umask. (Shotts, 2019)⁠ Think of umask as a bit mask which “shuts off” certain file permissions. Before we delve into this, let me just say that you won’t be using umask much at all (if ever), but it is very illuminating to know how file permissions get set, in my opinion.

Let’s take a look at an example. Here I printed my umask:

mislav@mislavovo-racunalo:~/Linux_folder$ umask

0022

Let’s take a hypothetical application which produces files with these permissions:

rw-rw-rw-

or in binary:

110110110

Then we apply umask to the default file permissions to mask certain bits of the file the application produced. Our umask in binary is (ignoring the leading (leftmost) zero):

000010010

So in the end we have:

110100100

We see that umask has “shut off” (turned to 0) the bits which correspond to the places where umask is 1.

To set your own umask, type:

umask newMask

I never had to mangle with this, but I think that it pays to know this because this term does tend to pop up from time to time in various tutorials. It also helps paint the picture of Linux.

Hope you learned something new!

References

Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 122-124

What is “umask” and how does it work? (n.d.). Retrieved February 10, 2020, from https://askubuntu.com/questions/44542/what-is-umask-and-how-does-it-work

NewsletterUpdates on interesting things I am doing

Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.

Leave a Reply

Your email address will not be published. Required fields are marked *