In Linux, CHMOD commands are often used on computers. Here is a detailed introduction. Every time you set invalid file properties in the province, you have to go to the online manual.
Only the administrator can execute CHMOD. Normal users can execute the command through sudo CHMOD.
Linux File permissions can be divided into three sections. Generally, the first column of LS-L is the File Permission information. The attributes of each file (any type of file or folder) are represented by 10 characters. Let's take a simple example and look at the following permission information:
Drwxr-XR-x
It can be seen that the first character is D, indicating that it is a folder. the first character of File Permission information is usually the link character "-".
The second to fourth digits (rwx) are the permissions of the file owner. The above characters are also very simple:
R: readable, W: writable, X: executable.
All the above information indicates that the folder owner is readable, writable, and executable to the folder. Use is all permissions.
Then, the fifth to seventh digits (R-x) are the permissions of the group where the folder owner is located. according to the above statement, this group has the readable and executable permissions on this folder. the Link number indicates no permission vacancy and no write permission.
Similarly, the eighth to tenth digits (R-x) are the permissions of others to operate on this folder. It seems to be readable and executable.
In fact, we can see more permissions composed of numbers. file permissions consist of user permissions, permissions of the user's group, and permissions of others. each permission can be an arbitrary combination of R, W, and X. therefore, it is too troublesome to use characters for representation. It is easier to simply use numbers for representation. we only need to remember three numbers.
Where: r = 4, W = 2, x = 1. I have never seen any. ^ o ^ with Linux permissions greater than 7.
Therefore, if it is readable and writable, the preceding three permissions can be calculated as follows: rwx = 4 + 2 + 1 = 7.
For example, the permission for reading a file is as follows:-RW-r --
This file is a common file, because the first letter is the connector "-", see the following three letters: RW-, indicating that the file owner can read and write the file. then, use numbers to represent 4 + 2 + 0 = 6,
Then, let's take a look at the 5-7 characters: r --, which indicates that the group in which the file owner is located only has the permission to read the file. The number is 4 + 0 + 0 = 4,
Check the last three characters: r --, which indicates other people's permissions on the file. It is also known as read. It is also indicated by numbers.
The permissions for all the files are shown as follows: 644
I have learned about the composition of permissions. Now it is convenient to use the CHMOD command.
Sudo chmod 644 readme.txt
In this way, the readme.txt file in the current directory is re-authorized. Only the owner can modify the file and others can only view the file content.
There is also a more convenient operation for a certain type of users. First, we will introduce two operators. "+" indicates adding permissions. "-" indicates reducing permissions.
The file owner can use the letter U. the user's group can be represented by the letter G. Others can use the letter O. The owner can use the letter.
It is actually the first letter of the word "user", "group", "other", and "all.
For example, execute readme.txt on a file to modify the permissions of others on this file. The modified bit can be written by others.
Sudo chmod o + W readme.txt
You can also modify the file by modifying the member of the user group:
Sudo chmod g + W readme.txt
If you want to remove the modifiable permissions of others for the file:
Sudo chmod o-w readme.txt
Finally, if we allow everyone to have all the permissions on the file, it is very dangerous to do so. It is only used for test examples.
Sudo chmod A + rwx readme.txt
OK. Here is a brief introduction. if you want to change the permission information of a directory and the files under it to a unified permission information, you can add the-R parameter. For example, if you want to change the permission information of the current directory test and the files under it, it should be readable and writable by the file owner, what others can only watch:
Sudo chmod-r 644 Test
Is it easy to calculate the meaning of a number by yourself?