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}}
I think this is better then what I wrote.