Skip to content

Instantly share code, notes, and snippets.

@igorshubovych
Last active March 26, 2019 13:48
Show Gist options
  • Save igorshubovych/bc024a1fa4e640622359 to your computer and use it in GitHub Desktop.
Save igorshubovych/bc024a1fa4e640622359 to your computer and use it in GitHub Desktop.
Documentation for chmod

chmod

Change the permission of a file or directory

  • Syntax

chmod {{who}} {{operation}} {{perm}} {{file}}

{{who}} is any combination of u (user), g (group), o (owner) or a (all)

{{operation}} is either + (giving permission) or - (removing permission)

{{perm}} is any combination of r (read), w (write), x (execute)

  • Give the user rights to execute a file/directory

chmod u+x {{file}}

  • Gives the user, group and owner rights to execute and read

chmod ugo+xr {{file}}

  • Removes executable rights from group

chmod g-x {{file}}

  • Use comma to separate the multiple permission sets

chmod u+r,g+x filename

  • Assign the permission recursively to directory

chmod -R u+x /path/to/directory/

Alternatively 3-digit number can be used to encode given permissions. Each digit represents permissions for (u)ser, (g)roup and (o)thers. Each digit is an octal number, bits give you permission to execute (bit 0), write (bit 1) and read (bit 2).

User    Group   Others
r w x   r w x   r w x
4 2 1   4 2 1   4 2 1
  • Give full permission to file owner, group and others can read and execute file

chmod 777 {{file}}

@Skyfold
Copy link

Skyfold commented May 22, 2014

I think this is better then what I wrote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment