Linux chmod usage

1. Different file types have different colors under LINUX

Green file: executable file, executable program  

Red file: compressed file or package file

Blue file: directory

White files: general files, such as text files, configuration files, source code files, etc. 

Light blue files: link files, mainly files created with the ln command

Flashing red: There is a problem with the linked file

Yellow: indicates the device file

Gray: indicates other files

2.chmod introduction

chmod +x means to give execution permission

chmod +x turns ordinary files (gray) +x into green

chmod -x turns executable files (green) into ordinary files (gray)

chmod a+x

u stands for user. 
g stands for user group. 
o stands for others. 
a stands for all.

This means that chmod u+x somefile only grants execution permission to the owner of this file 
and chmod +x somefile is the same as chmod a+x somefile 

chmod 777 file or directory

Example: chmod 777 /etc/squid After running the command, the permissions of the squid folder (directory) are modified to 777 (readable, writable and executable)

In the Linux system, the roles and permissions of each user are very detailed and strict. Each file (directory) has access permissions. This mechanism is used to determine that a user can access the file (directory) in a certain way. Perform operations such as reading, writing, and execution.

There are 3 different types of users who manipulate files or directories: file owners, group users, and other users. The highest bit represents the permission value of the file owner, the middle bit represents the permission value of the group user, and the lowest bit represents the permission value of other users. Therefore, in chmod 777, the three numbers 7 correspond to the above three users, and the permission values ​​are all For 7.

File or directory permissions are divided into three types: read-only, write-only, and executable.

Authority Permission value Binary Specific action
r 4 00000100 r ead, read. The current user can read the content of the file, and the current user can browse the directory.
w 2 00000010 w rite, write. The current user can add or modify the content of the file, and the current user can delete or move the directory or files in the directory.
x 1 00000001 e x ecute, execute. The current user can execute files, and the current user can enter the directory.

 

 

 

 

According to the above table, the permission combination is the sum of the corresponding permission values, as follows:

7 = 4 + 2 + 1 Read and run permissions
5 = 4 + 1 Read and run permissions

4 = 4 read-only access

 

Therefore, everyone understands the   meaning of the  chmod 754 filename command.

The meaning of this command is to give the file owner the read and run permission of the filename file, give the group user the read and run permission, and give the read permission to other users.

For more official and detailed explanations, you can use the following command to view:

chmod --help or

man  chmod

Guess you like

Origin blog.csdn.net/weixin_41882459/article/details/110632551