Here is the video version, if you prefer it:
Let’s talk about how to change the permissions of a file. To do so, let’s first talk about octal and binary numbers. Before you get all whiny and say “Oh jeez, why binary? Why do I need to know binary?”. Well, you don’t really, but I think it greatly simplifies things, so that’s why.
Let’s look at user permissions (same applies for group and world permissions). If you have:
that could be represented in binary as:
since binary has only two digits –
1 – so this could be a valid choice. We have a
1 where we have the right to modify the file in a certain way “enabled” and
0 where we have the right to modify the file in a certain way disabled.
Now, how do we read
110 in binary? Let’s first see how do we read it in decimal.
What you actually do is this:
110 is 0 * 10^0 + 1 * 10^1 + 1 * 10^2 (looking the digits from right to left, where
^ is the exponentiation operator). That is, the rightmost digit is the least significant one and it gets multiplied by
10^0. The digit to the left of it is multiplied by
10^1 and so on. The same is in binary, but instead of using base
10, we use base
110 will be:
0 * 2^0 + 1 * 2^1 + 1 * 2^2 = 6
Now, let’s pay attention to the highest possible number with 3 digits in binary, which is
111. By following the same logic
111 in binary is
7 in octal (
1 * 2^0 + 1 * 2^1 + 2 * 2^2 = 7). Note that octal has 8 digits –
So now, the problem reduces to: Figure out what octal digit represents the file permissions we want. Let me give you a list:
0in octal –
1in octal –
2in octal –
3in octal –
4in octal –
5in octal –
6in octal –
7in octal –
When you look at binary representations of the octal numbers, you can see the correspondence. For example,
5 in octal is
101 in binary, which would look like
r-x, meaning we are able to read and execute the file in question.
Now we can come to
chmod is used to change file permissions. It is used as follows:
chmod <filePermissions> <file>
<filePermissions> are 3 octal numbers in a row, each representing permissions for the user, the group and the world, respectively. Only the file owner or the superuser can change file permissions. (Shotts, 2019)
mislav@mislavovo-racunalo:~/Linux_folder$ chmod 600 aba.txt
You can also use symbolic notation to change permissions (you can check out the man pages for
chmod or you can Google how to use symbolic notation with
chmod), but I believe that octal is easier to use once you understand it. I do use
chmod +x file to add executable permissions to a file and that is a fast way to do so, but whenever I need anything more that that, I use binary file permissions.
Hope you learned something useful!
Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 118-122