CHMOD (chmod) is a UNIX oriented command that means “Changing Mode.” It lets you change the mode (hence the name) of the file, or directory(ies) depending on how the chmod command is used. When I say “changing mode,” I mean giving the file a different permission scheme, respectively read, write, and execute. This command, by the way, is one of the most useful and most used commands in Linux.
Basically modes are a simple way of saying permissions. There are a few exceptions to this rule, but they aren't part of this article. There are three basic modes: -r (read), -w (write), -e (execute). See the chmod figure.
CHMOD Figure
Later in this article, I’ll explain how you can find out the number system for certain modes (permissions). Modes to a basic extent is very easy and simple. You have three numbers: the first number is for the owner, the second for the group, and the third for the world. Depending upon the numbers, you will get a certain permission assigned to the respective object. We will use the examples from above:
Bash
chmod -v 755 /Test
This states that the owner is assigned Read, Write, and Execute permissions; groups that are assigned to the file/directory get Read and Execute permissions; world (other) also gets Read and Execute permissions.
Take a break. Drink some coffee or tea. If you're avoiding caffeine, do 100 jumping jacks. Then come back for the fun part: binary/octet conversion.
The Structure of chmod octet
You see octets all the time. If you recall, an IP address is a series of four (4) octets. Simply put, an octet is eight bits of data. So in an IP address you have your localhost (127.0.0.1). You have four octets: 127, 0, 0, and 1. We now have to go back to remembering binary. Even though it might be a one (1) it is still set in binary as 0001, which is 1 bit of data. With an IP address, however, it is viewed as eight bits in binary, so it would look like 00000001, thus the eight bits - octet (Figure 1).
Figure 1
So what’s this have to do with chmod? Well, in order to make permissions with chmod using the numerical format, you have to know how to convert the permission (binary) to octet. Read = 4, Write = 2, Execute = 1. Do you see the pattern? If you don’t, look at Figure 1; it goes: 1, 2, 4, 8, 16, and so on. We only need the first three bits of binary: 1, 2, and 4. This is a simple structure of the chmod’s octet.