Skip to content

Understanding file permissions – Part 3

Beginner's Linux

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.

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!

Like this post?

If you would like to support the time and effort I have put into my tutorials and writing, please consider making a donation.

One Comment

  1. Chris wrote:

    You’re a god. Thank you!

    Monday, September 25, 2006 at 23:27 | Permalink | Using Mozilla Firefox Mozilla Firefox 1.5.0.7 on Windows Windows XP

1 Trackbacks/Pingbacks

  1. […] Understanding file permissions – Part 3 […]

  2. […] Understanding file permissions – Part 3 […]

  3. RambleOn » Blog Archive » Understanding file permissions on Wednesday, September 27, 2006 at 02:15

    […] Friend/Poddevver Peter Upfold has posted the 3rd part of his Linux tutorial, Understanding File Permissions. It’s a fantastic guide to understanding the way that file permissions work in Linux, since its often confusing for us new users! […]

  4. FOSSwire » Understanding file permissions - Part 1 on Monday, November 6, 2006 at 20:30

    […] Part 2 is now online and available – read it now! Also Part 3 is available (but read Part 2 first!). […]

  5. FOSSwire » Understanding file permissions - Part 2 on Sunday, November 12, 2006 at 20:22

    […] When you’re ready, move on to Part 3 [Coming soon to FOSSwire], or revisit Part 1. […]

  6. […] you’re ready, move on to Part 3, or revisit Part […]

  7. […] 2 is now online and available – read it now! Also Part 3 is available (but read Part 2 […]

Post a Comment

On some sites, you must be logged in to post a comment. This is not the case on this site.
Your email address is not made public or shared. Required fields are marked with *.
*
*
*

Posting a comment signifies you accept the privacy policy.
Please note — usually your comment will appear straight away but sometimes it will be held for approval (this is due to the spam filter). If your comment is waiting to be approved, please don’t post it again! It will appear eventually.