chmod [options] mode[,mode] file1 [file2 ...]
change the permission for one or several files
Examples
Add execute-by-user permission to file:
chmod u+x file
Either of the following will assign read/write/execute permission by owner (7), read/execute permission by group (5), and execute-only permission by others (1) to file:
chmod 751 file chmod u=rwx,g=rx,o=x file
Any one of the following will assign read-only permission to file for everyone:
chmod =r file chmod 444 file chmod a-wx,a+r file
The following makes the executable setuid, assigns read/write/execute permission by owner, and assigns read/execute permission by group and others:
chmod 4755 file
chmod 777 it can be read/write and execute
Permissions
r Read.
w Write.
x Execute.
s Set user (or group) ID.
t Sticky bit; used on directories to prevent removal of files by non-owners.
u User’s present permission.
g Group’s present permission.
o Other’s present permission.
# | Permission | rwx |
---|---|---|
7 | full | 111 |
6 | read and write | 110 |
5 | read and execute | 101 |
4 | read only | 100 |
3 | write and execute | 011 |
2 | write only | 010 |
1 | execute only | 001 |
0 | none | 000 |
Options
-c, –changes
Print information about files that are changed.
-f, –silent, –quiet
Do not notify user of files that chmod cannot change.
–help
Print help message and then exit.
-R, –recursive
Traverse subdirectories recursively, applying changes.
–reference=filename
Change permissions to match those associated with filename.
-v, –verbose
Print information about each file, whether changed or not.
–version
Print version information and then exit.
users
(the fist letter)
u ser
g roupe
o ther
a ll (default)
Opcode
+ for Add permission.
- for remove permission
= for Assign permission (and remove permission of the unspecified fields).