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:
Let’s take a hypothetical application which produces files with these permissions:
or in binary:
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):
So in the end we have:
We see that
umask has “shut off” (turned to
0) the bits which correspond to the places where
To set your own umask, type:
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!
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
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.