chmod
[option] mode filesChange the access mode of one or more files. Only the owner of a file or a privileged user may change its mode. Create mode by concatenating the characters from who, opcode, and permission. who is optional (if omitted, default is a
); choose only one opcode.
-f
Suppress error message upon failure to change a file's mode.
-R
Recursively descend directory arguments while setting modes.
u | User |
g | Group |
o | Other |
a | All (default) |
+ | Add permission |
- | Remove permission |
= | Assign permission (and remove permission of the unspecified fields) |
r | Read |
w | Write |
x | Execute |
s | Set user (or group) ID |
t | Sticky bit; save text mode (file) or prevent removal of files by nonowners (directory) |
u | User's present permission |
g | Group's present permission |
o | Other's present permission |
l | Mandatory locking |
Alternatively, specify permissions by a three-digit sequence. The first digit designates owner permission; the second, group permission; and the third, others permission. Permissions are calculated by adding the following octal values:
4 | Read |
2 | Write |
1 | Execute |
Note: a fourth digit may precede this sequence. This digit assigns the following modes:
4 | Set user ID on execution |
2 | Set group ID on execution or set mandatory locking |
1 | Sticky bit |
Add execute-by-user permission to file:
chmod u+x
file
Either of the following assigns read-write-execute permission by owner (7), read-execute permission by group (5), and execute-only permission by others (1) to file:
chmod 751
filechmod u=rwx,g=rx,o=x
file
Any one of the following assigns read-only permission to file for everyone:
chmod =r
filechmod 444
filechmod a-wx,a+r
file
Set the user ID, assign read-write-execute permission by owner, and assign read-execute permission by group and others:
chmod 4755
file