Linux file management command-chmod command

 

1. Function

Linux/Unix file calling permissions are mainly divided into three levels: file owner, group, and others. Use the chmod command to control how the file is called by others.

 

2. Grammar

chmod [-cfvR] [--help] [--version] mode file…

 

Three, parameter description

Scope of authority:

u: The owner of the file, that is, the current user.

g: The owner of the file belongs to the same group, that is, the current group.

o: Users or groups other than the current user or current group of the file.

a: All users and groups.

Permission code:

r: indicates that it can be read, and the number 4 is used instead.

w: Indicates that it can be written, and the number 2 is used instead.

x: means executable, use the number 1 to replace it

Other parameters:

+: Indicates to increase permissions.

-: Indicates delete permission.

=: Indicates the only setting authority.

-c: Report processing information when file permissions are changed.

-R: Make the same permission changes to all files and subdirectories in the current directory.

-v: Display the detailed information of the permission change.

-f: Don't display an error message if the file permissions cannot be changed.

--version: Display version information.

--help: Display help information.

 

Four, usage

The chmod command is mainly used to control the access permissions of Linux system files or directories.

The chmod command mainly uses two methods:

★ One is a text setting method that includes letters and operator expressions;

★ One is the number setting method that includes numbers.

 

Example 1 : -rw-r--r--

-rw-r--r--

Analysis: The first character indicates the file type.

If the first character is d, it means that this is a folder;

If the first character is l, it means that this is a connection file;

If the first character is -, it means that this is a normal file.

 

The following 9 characters represent permissions, and the 9 characters are divided into 3 groups, each with 3 characters.

The first group represents the permissions of the user who created this file;

The second group represents the authority of the group of the user who created the file;

The third group represents the permissions of other users.

 

Among the 3 characters in each group, the first character represents read permission, the second character represents write permission, and the third character represents execution permission.

So here it means that this is a normal file, the permission of the user who created the file is rw-, the permission of the group of the user who created the file is r--, and the permissions of other users are r--.

 

Example 2 : chmod 761

chmod 761 means: the permission set for the user who creates the file is 7, 7=4+2+1, so it means that the user who creates the file is given the read, write and execute permissions. 6=4+2, that is to say, grant read and write permissions to the group of the user who created the file, and the last 1 represents the execution permission, that is to say, grant the execution permission to other users.

 

Example 3: Add executable permissions to all users and groups of test.txt

chmod a+x test.txt

Example 4: Delete the original permissions of the current user of the test.txt file, and then make it have readable, writable, and executable permissions, and output processing information.

chmod u=rwx test.txt -c

Example 5: Make the test.txt file readable by everyone

chmod ugo+r test.txt 或者 chmod a+r test.txt

Example 6: Set the file test1.txt and test2.txt as the file owner, who can write in the same group as the file, but cannot be written by other people.

chmod ug+w,o-w test1.txt test2.txt

Example 7: Set the test.txt file to be executed only by the owner of the file

chmod u+x test.txt

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_43184774/article/details/106062766