Follow me on Twitter for my latest adventures!
There are two ways you can change file permissions in Unix - one is using
chmod's symbolic (text) modes (like
chmod ug+x file), the other is using the octal modes (like
chmod 0660 file). It turns out that symbolic modes are more powerful because you can mask out the permission bits you want to change! Octal permission modes are absolute and can't be used to change individual bits. Octal modes are also sometimes called absolute because of that.
Here is an example that illustrates that.
Suppose you have this file,
$ ls -las file 0 -rw-rw---- 1 pkrumins cats 0 Feb 25 12:49 file
and you want to set the execute
x bit for everyone. If you use symbolic modes, you can just do,
$ chmod a+x file $ ls -las file 0 -rwxrwx--x 1 pkrumins cats 0 Feb 25 12:49 file
But, if you're used only to absolute modes, then you first need to calculate the existing permission mask, which would be 0660, and then calculate the new one by adding the 1 to each group, so the end result would be 0771,
$ chmod 0771 file $ ls -las file 0 -rwxrwx--x 1 pkrumins cats 0 Feb 25 12:49 file
It's still easy with octal modes, but why do it the harder way when you can just
chmod a+x file, right?
I'd also like to note that symbolic modes are a feature of
chmod utility. If you look at chmod system call, it only takes the octal mode. The
chmod utility first does a stat to determine the existing mode, then calculates the new one. It does the calculation for you. So don't do it again yourself!