Remind me how to use chmod and chown to set unix file permissions again

September 05, 2011

I don’t use Unix often enough to remember all the little shortcuts and codes that proper geeks know. I don’t speak the language well enough. So I can never remember what the deal is with file permissions. I can remember that chmod 777 means letting anyone do what they want with the file, and I can remember that the numbers mean owner, group, others, but beyond that I need to look stuff up. For some reason, I can never seem to find a simple translation of what each file permission means. All very elegant, and avoids wasting bits, but sometimes I wonder if maybe this is geeks being like lawyers, deliberately shrouding things in unnecessary complication in order to frighten outsiders away. Who the hell knows about octal numbers? Anyway, for future reference, here are the codes that most people need to use.

Octal Group permissions What it means
777 -rwxrwxrwx Anyone can read, write or execute
755 -rwxr-xr-x Owner can do anything, others can just read and execute
644 -rw-r--r-- Owner can read and write, others can just read

While I’m here, I’ll make a note of how it all works:

Number positions

  • First number = owner
  • Second number = group
  • Third number = others

Number meanings (add them together)

  • Read = 4
  • Write = 2
  • Execute = 1

Set a directory and its contents to be editable by the owner, readable and executable by others

chmod -R 755 directory-name/

Set the owner and group of the directory and its contents.

The other thing I can never remember is the syntax of chown, so here’s an example:

chown -R developer:developer directory-name