Changing Permissions with chmod Binary Values

Written by Mark Sanborn: 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

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. For our firt number, ‘111’:

… 128 64 32 16 8 4 2 1

1 1 0

All you do now is add up the numbers 4 + 2 + 0 = 6 ‘100’ would be, 4 + 0 + 0 = 4

To change the permissions of a file you use chmod. For example:

chmod 644 test.txt

Common chmod values

777 - readwrite by all 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.

Share: