Detailed explanation of Linux chmod command

chmod - change the access mode of one or more files (mode)
 
chmod [options] mode files
 
Only the file owner or privileged user can use this function to change the file access mode. mode can be numeric or expressed as who opcode permission. who is optional and defaults to a (all users). Only one opcode can be selected. Multiple modes can be specified, separated by commas.
 
options:
 
-c,--changes
Only output information about changed files
 
-f,--silent,--quiet
Do not notify users of files when chmod cannot change file modes
 
--help
Output help information.
 
-R,--recursive
It can recursively traverse subdirectories and apply changes to all files and subdirectories in the directory
 
--reference=filename
Set permissions by referring to the permissions of filename
 
-v,--verbose
Whether the modification is successful or not, output the information of each file
 
--version
Output version information.
 
who
 
u
user
 
g
Group
 
O
other
 
a
All users (default)
 
opcode
 
+
Increase permissions
 
-
remove permission
 
=
Reassign permissions
 
permission
 
r
read
 
w
Write
 
x
implement
 
s
Set the ID number of the user (or group)
 
t
Set the sticky bit to prevent files or directories from being deleted by non-owners
 
u
User's current permissions
 
g
the current permissions of the group
 
O
Current permissions of other users
 
As an option, we mostly use three-digit octal numbers to represent permissions. The first digit specifies the permissions of the owner, the second digit specifies the group permissions, and the third digit specifies the permissions of other users. The sum of three values ​​(write) and 1 (execute) determines the authority. For example, 6 (4+2) represents read and write rights, and 7 (4+2+1) has read, write and execute rights.
 
The fourth digit can also be set, which is located in front of the three-digit permission sequence. The fourth digit is 4, 2, and 1, which means the following:
 
4,执行时设置用户ID,用于授权给基于文件属主的进程,而不是给创建此进程的用户。
 
2,执行时设置用户组ID,用于授权给基于文件所在组的进程,而不是基于创建此进程的用户。
 
1,设置粘着位。
 
实例:
 
$ chmod u+x file                      给file的属主增加执行权限
$ chmod 751 file                      给file的属主分配读、写、执行(7)的权限,给file的所在组分配读、执行(5)的权限,给其他用户分配执行(1)的权限
$ chmod u=rwx,g=rx,o=x file      上例的另一种形式
$ chmod =r file                     为所有用户分配读权限
$ chmod 444 file                   同上例
$ chmod a-wx,a+r   file          同上例
$ chmod -R u+r directory           递归地给directory目录下所有文件和子目录的属主分配读的权限
$ chmod 4755                            设置用ID,给属主分配读、写和执行权限,给组和其他用户分配读、执行的权限。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326687219&siteId=291194637