FANDOM


chmod is a Linux and OS X command that changes the permissions of a file.

Octal Permissions

Files have a specified owner (a single user) and group (a bunch of users). File permissions are stored in three parts:

  1. The owner's permissions
  2. The group members' permissions
  3. Everyone else's permissions

Each of these individual permissions is made of three bits: Read, Write, and eXecute.

Viewing Permissions and Ownership

Run

ls -l filename

The output should look something like

-rwxr-xr-- 1 lvuser root 420 Apr 20 04:20 filename

We only really care about the second through tenth characters (i.e. the first chunk, except the first character. If you really care, a dash means a file, and "d" means directory). In this example,

  1. The owner can read, write, and execute (rwx)
  2. The group members can read and execute only (r-x)
  3. Everyone else can only read (r--)

Writing Permissions in Octal

Convert the triplets to binary in the obvious way (rwx=111, r--=100, etc.). Then just convert these to octal. Join them together into a three digit octal number (754 in our example above). Congrats, you did it!

Changing Permissions

All at once

Use the syntax

chmod 754 filename

to change the permissions of filename to 754

Individually

Use the syntax

chmod [ugoa]*[+-=][rwx]* filename

Where brackets mean choose one of the symbols. The asterisk means you can do it multiple times, so

chmod ug+rx filename
chmod o+w filename
chmod a-w filename

are all valid. Note that

  • u means owner
  • g means group
  • o means everyone
  • a is equivalent to ugo

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.