Why use `chmod 644` instead of `chmod u=rw,go=r,…`

chmodpermissions

I've been working on *nix for a few years now, and one of the things I just can't get used to is octal permissions in code. Is there some other reason than line length to prefer chmod 644 ... over chmod u=rw,go=r ...?

PS: I'm not looking for an explanation of octal permissions. I know how they work, and it's well explained in the manual. I'm asking why octal seems to be preferred over the more human-readable form.

Best Answer

Using the octal codes has two advantages I can think of, neither of which is that huge:

  1. They're shorter, easier to type.
  2. A few things only understand them, and if you routinely use them you'll not be scratching your head (or running to documentation) when you run into one. E.g., you have to use octal for chmod in Perl or C.

Sometimes really simple utilities won't handle the "friendly" versions; especially in non-GNU userlands.

Further, some utilities spit out octal. For example, if you run umask to see what your current umask is, it'll spit it out in octal (though in bash, umask -S does symbolic).

So, in short, I'd say the only reason to prefer them is to type fewer characters, but that even if you elect not to use them, you should know how they map so that you can figure out an octal code if you run into one of the things that only does octal. But you don't need to immediately know that 5 maps to rx, you only need to be able to figure that out.