chmod mode file ...
chmod
command can be used to modify the file mode of files and directories.chmod
command can also be used to modify the Access Control Lists (ACLs) associated with files and directories: chmod -- change file ACLs (Access Control Lists).rwxrwxrwx
)
that define the read, write, and execute permissions for the user, group, and others.
The first 3 bits defines the read, write, and execute permissions for the user,
the next three bits for the group,
and the last three bits for others.umask
(default 002
).
To set the permission of the new created file (or directory),
the value of umask 002
is combined with the default permissions of a file which is 666
(or directory 777
).
So by default a new created file has the permissions rw-rw-r--
(664
)
and new created directory has the permissions rwxrwxr-x
(775
).read
", "write
", and "execute
" to "user
", "group
", and "others
" on the file "file1".$ chmod 777 file1 $ chmod ugo+rwx file1 $ chmod ugo=rwx file1 $ chmod a=rwx file1
read
", "write
", and "execute
" to "user
"
and set the permission "read
" and "execute
" to "group
" and "others
" on the file "file1".$ chmod 755 file1 $ chmod u=rwx,go=rx file1 $ chmod u=rwx,go=u-w file1
read
" and "write
" to "user
" and "group
" on the file "file1".$ chmod ug+rw file1
read
" and "write
" to "user
" and "group
" on the file "file1".$ chmod ug-rw file1
group
" and "others
" on the file "file1".$ chmod go-rwx file1 $ chmod go= file1
read
", "write
", and "search/execute
" to "user
", "group
", and "others
" on the directory "folder1" and all its files and sub-directories.$ chmod -R 777 folder1/ $ chmod -R ugo+rwx folder1/ $ chmod -R ugo=rwx folder1/ $ chmod -R a=rwx folder1/
-R |If chmod is applied to a directory, it will change the mode of this directory and all its files and sub-directories. |By default, the linked files of symbolic links will not be changed.
-L |If the -R option is specified, the linked files of symbolic links will be changed.
-v |Cause chmod to be verbose, showing filenames if the mode is modified. |If the -v flag is specified twice, the old and new modes of the file will also be printed, in both octal and symbolic notation.
[ugoa]*([-+=]([rwx]*|[ugo]))+
mode ::= clause [, clause ...] clause ::= [who ...] [action ...] action action ::= operation [permission ...] who ::= u | g | o | a operation ::= + | - | = permission ::= r | w | x | u | g | o
u: user g: group o: others a: all (equivalent to "ugo")
r: read permission. w: write permission. x: execute permission (files) | search permission (directories).
r (read) = 4 w (write) = 2 x (execute) = 1
r+w (read and write) = 6 r+x (read and execute) = 5 w+x (write and execute) = 3
r+w+x (read and write and execute) = 7
+ |If no value is supplied for permission, the "+" operation has no effect. |If no value is supplied for who, each listed permission is set for the owner. |Otherwise, the mode of the specified who and permission values are set.
- |If no value is supplied for permission, the "-" operation has no effect. |If no value is supplied for who, each listed permission is cleared for the owner, group and others. |Otherwise, the mode of the specified who and permission values are cleared.
= |If no value is supplied for permission, all permissions are cleared for the listed values of who. |If no value is supplied for who, each listed permission is set and non listed permission is cleared, for the owner, group and others. |If no value is supplied for both permission and who, all permissions are cleared for the owner, group and others. |Otherwise, each listed permission is set and non listed permission is cleared, for the listed values of who.