It’s back! Well, it’s about time for Part 3 of my file permissions tutorial. Just before we get stuck in to the gory details of the content of this tutorial, it’s worth mentioning that it’s a good idea to read up on Part 1 and Part 2 before trying this, especially if you know nothing about file permissions on Linux.
Right, let’s get started!
Chmodding the number way
The one last thing I didn’t cover in Part 2 was using the number system to change permissions at the command line. By the way, you don’t have to know this method, but some people find it easier and quicker once they’ve remembered the number sequences they need.
Right, OK. The number method uses the digits 0-7 to represent the patterns of rwx we learnt about in Part 1. The table below illustrates which pattern corresponds to which number.
rwx | Number |
---|---|
--- |
0 |
--x |
1 |
-w- |
2 |
-wx |
3 |
r-- |
4 |
r-x |
5 |
rw- |
6 |
rwx |
7 |
So to make our set, we simply work out the relevant number for each of the three parts, and we get three digits from 0-7 representing the permissions.
Then, we simply pass these three digits to chmod as normal.
$ chmod 664 myfile
So that would give us 644, which works out as -rw-rw-r–. Simple!
It really is that simple, and if you memorise the possibilities (in fact you don’t even need to remember them all, usually, 0, 4, 5, 6 and 7 will suffice for normal uses) it can be a lot faster to use the numbers than it is to enter a complicated string of letters and symbols.
And quite surprisingly, this pretty much brings us to the end of Part 3! You could argue I should have added this to Part 2, but I really didn’t want to make Part 2 far too long-winded and bloated.
Why 0-7, what’s the significance?
This section is strictly voluntary. At this point, you should be able to proficiently edit permissions in all three methods without reading any further. This section is purely if you are interested in the reason why we use these digits.
Basically, it’s a binary thing. Each permission can be represented as one bit, either on or off. Thus we can end up with a string of bits as our permissions setting.
For example, rwxrwxrwx would be translated as 111111111, as all the permissions are on. Similarly, rwxrw—- is 111110000. The number we used above is simply the relevant binary number converted into octal (base 8, digits 0-7, as opposed to decimal, base 10, digits 0-9). This octal number is three digits long, as three bits equals one octal digit.
It’s that octal number that I showed you in the table, I just skipped the binary step for you. I thought that would be better as a voluntary additional reading section.
Further reading
There are a couple of very geeky permission topics I didn’t cover here, including set UID, set GID and sticky bit. For most uses of Linux, you don’t need to know or understand these. I might revisit them if the topic comes up later, but for now I’ll just link to some other permissions tutorials that include it.
- Dave Eisenberg’s chmod Tutorial – a more in-depth tutorial covering the things we haven’t mentioned
If anyone else has any useful links that might benefit readers of this tutorial, post a comment and I’ll consider your suggestion.
And as with all my tutorials, if you’ve got any suggestions, had a few problems or you genuinely found this useful, I’d love it if you’d drop a comment on this post, it makes writing these so worthwhile!
You’re a god. Thank you!