Changing Permissions with chmod Binary Values

Last updated: Mar 20, 2008

Recently I accidently changed the permissions of one of my files and I didn’t know what the correct permissions were suppose to be. I did know that the other files in the same directory were the correct permission. Using the ls -l command. I was able to see that the permission was set as, -rw-r–r–. Great, I now know the correct permission; however, I usually use the binary syntax for chmod and I am not familiar with the other method.

What I ended up doing was a little weird and geeky but in the end it was fun and I got my permissions fixed. I actually converted the character method to binary by hand and then ended up changing the permission with my usual method.

Converting -rw-r–r– Format to Binary

The easiest way I found was to convert each character to a ‘1’ and each dash to a ‘0’.

So -rw-r--r-- would equal to: 0110100100

I then would then drop the first number and group it into threes. Here is the binary conversion to our 10 based system.

110 100 100 = 644
 6   4   4

... 128 64 32 16 8 4 2 1
                   1 1 0
           4 + 2 + 0 = 6

So to match the permissions of the other files in the directory I can do this:

$ chmod 644 test.txt

Quick Lesson on Binary

If you don’t know binary its actually quite easy. It goes from right to left like this:

… 128 64 32 16 8 4 2 1

Think of the 1s and 0s as switches. On and off. Let’s convert binary ‘111’:

... 128 64 32 16 8 4 2 1
                   1 1 1
           4 + 2 + 1 = 7

All you do now is add up the numbers 4 + 2 + 1 = 7.

Let’s convert ‘100’:

... 128 64 32 16 8 4 2 1
                   1 0 0
           4 + 0 + 0 = 4

Let’s choose an arbitrary number 17:

... 128 64 32 16 8 4 2 1
               1 0 0 0 1
 16 + 0 + 0 + 0 + 1 = 17

octal (base-8) permission codes

  • 0 (binary 000) – No permissions.
  • 1 (binary 001) – Execute permission.
  • 2 (binary 010) – Write permission.
  • 3 (binary 011) – Write and execute permissions.
  • 4 (binary 100) – Read permission.
  • 5 (binary 101) – Read and execute permissions.
  • 6 (binary 110) – Read and write permissions.
  • 7 (binary 111) – Read, write, and execute permissions (full permissions).

Common chmod values

These number can be applied to owner, group, and others:

  • 777 - readwrite by all, owners, group, and others
  • 755 - Read by Owner + Write by Owner + Execute by Owner + Read by Group + Execute by Group + Read by anyone (common for files in user’s home directory)
  • 644 - Everyone read, only owner can write.

Here are some more Linux commands.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on

Share: