chmod by the Numbers

Up to this point, we’ve been setting the mode with letters. It turns out that you can also set the mode numerically. Here’s how it works:

  1. Write the permissions you want the file to have. To make your life easier, write the permissions grouped into sets of three letters. For example, let’s say you want file info.sh to have these permissions

    - rwx r-x r-- info.sh
    
  2. Under each letter, write a digit 1; under each dash write a digit zero. Ignore the dash at the very beginning that tells you whether it’s a file or directory. This gives you three binary numbers.

    - rwx r-x r-- info.sh
      111 101 100
    
  3. Now convert each set of three digits to a single digit using this table:

    BinaryBecomes
    0000
    0011
    0102
    0113
    BinaryBecomes
    1004
    1015
    1106
    1117

    From our example, the 111 101 100 translates to the number 754.

  4. Now use that number in a chmod command to set your desired permissions on the file:

    chmod 754 info.sh
<< chmod Quick Reference Summary Index Numeric Mode in Action >>