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.

  <td>
    &nbsp;Group permissions
  </td>
  
  <td>
    What it means
  </td>
</tr>

<tr>
  <td>
    777
  </td>
  
  <td>
    <tt>-rwxrwxrwx</tt>
  </td>
  
  <td>
    Anyone can read, write or execute
  </td>
</tr>

<tr>
  <td>
    755
  </td>
  
  <td>
    -rwxr-xr-x
  </td>
  
  <td>
    Owner can do anything, others can just read and execute
  </td>
</tr>

<tr>
  <td>
    644
  </td>
  
  <td>
    -rw-r--r--
  </td>
  
  <td>
    Owner can read and write, others can just read
  </td>
</tr>

<tr>
  <td>
    &nbsp;
  </td>
  
  <td>
    &nbsp;
  </td>
  
  <td>
    &nbsp;
  </td>
</tr>
Octal
While I'm here, I'll make a note of how it all works: \* Number structure \* First number = owner \* Second number = group \* Third number = others \* Number meanings (add them together) \* Read = 4 \* Write = 2 \* Execute = 1

chmod -R 755 directory-name/ The other thing I can never remember is the syntax of chown, so here’s an example: chown -R developer:developer directory-name Set the owner and group of the directory and its contents.