This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12202|Reply: 0

[linux] Linux chmod command explained in detail

[Copy link]
Posted on 1/12/2016 9:09:08 PM | | |

chmod [options] mode files

Only the file owner or privileged user can use this function to change the file access mode. mode can be in numerical form or expressed in the form of who opcode permission. Who is optional, default is A (all users). Only one opcode can be selected. Multiple modes can be specified, separated by commas.

options:

-c,--changes
Only the information of the changed file is output

-f,--silent,--quiet
When chmod cannot change the file mode, the user of the file is not notified

--help
Output help information.

-R,--recursive
You can recursively traverse the subdirectory and apply the modification to all files and subdirectories in the directory

--reference=filename
Refer to the filename permission to set the permissions

-v,--verbose
Regardless of whether the modification is successful or not, output information for each file

--version
Output version information.

who

u
user

g
group

o
Others

a
All Users (Default)

opcode

+
Increase permissions

-
Remove permissions

=
Reassign permissions

permission

r
Read

w
write

x
execute

s
Set the ID number of the user (or group).

t
Set a sticky bit to prevent files or directories from being deleted by non-owners

u
The user's current permissions

g
The group's current permissions

o
Current permissions for other users

As a choice, most of us use the form of three-digit octal numbers to represent permissions, the first to specify the permissions of the master, the second to specify the permissions of the group, and the third to specify the permissions of other users, each by the sum of three values: 4 (read), 2 (write), and 1 (execute) to determine the permissions. For example, 6 (4+2) represents the right to read and write, and 7 (4+2+1) has the right to read, write and execute.

You can also set the fourth digit, which is located in front of the three-digit permission sequence, and the fourth digit is 4, 2, 1, which means the following:

4. Set the user ID during execution, which is used to authorize the process based on the file owner, not to the user who created the process.

2. Set the user group ID during execution, which is used to authorize the process based on the group where the file is located, not based on the user who created the process.

1. Set the adhesive position.

Instance:

$ chmod u+x file adds execution permissions to the owner of the file
$ chmod 751 file assigns read, write, and execute permissions to the file's owner (7), reads and executes (5) to the file's group, and assigns execution (1) permissions to other users
$ chmod u=rwx,g=rx,o=x file Another form of the example above
$chmod=r file assigns read permissions to all users
$ chmod 444 file Same as above
$ chmod a-wx, a+r file as above
$ chmod -R u+r directory recursively assigns read permissions to the owner of all files and subdirectories in the directory
$ chmod 4755 sets the ID to assign read, write and execute permissions to the subordinate, and assign read and execute permissions to the group and other users.




Previous:C# divides arrays into two groups, two in groups
Next:Linux commonly uses chmod commands
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com