Linux files are divided into three identities and four permissions.
u: The owner of the file
g: The group the file belongs to
o : Other users
For each identity, there are four permissions, namely:
r: permission to read files (read )
w: Permission to write files (write)
x: Permission to execute (execute)
s: Special permissions
In the detailed explanation of Linux file permissions, we know that there are two ways to represent file permissions in Linux, namely numerical and symbolic representation.
chmod 755 test.sh
Convert 755 into character form, which is rwxr-xr-x, That is to say, the file owner, the group to which it belongs, and other users can read and run the test.sh file, but only the owner can write to the file, which means that other people do not have the right to modify the test.sh file. (Of course, root users do not have this restriction. Anyone who wants to change can do it. This is also an experience that reflects the supreme power of the root account!)
It is relatively simple to change the permissions of files through mathematical forms. As long as the calculation is done well, the files need to be changed. Grant the permissions, and then call the chmod command. The calling form is:
chmod new permission file list
chmod +x test.sh
The mathematical form can change the four permissions of all three identities of the file at one time, while the character form is more flexible and can be given to a certain identity. A certain permission is set separately. For example, the above command is to grant execution permission to all three identities. You can also set it separately:
chmod u+x test.sh Add only to the owner Add executable permissions
chmod g+x test.sh Add executable permissions only to group identities
chmod o+x test.sh Add executable permissions only to other people's identities
The above three instructions together are equivalent to the above instruction. They are all functions that enable executable permissions for all identities. You can also operate as follows:
chmod a+x test.sh
The a here represents all 3 identities!
If you want to remove a certain permission of a certain identity, you only need to change + to -. For example, to remove the executable permissions of other people’s identities:
chmod o-x test. sh
For read, write and other permissions, just practice as above. The operation of chmod to change file permissions in character form is as shown in the table below:
|
ug oa |
+(plus)-(minus)=(SET) | rwx |
|
chmod u=rwx,g+rx,o-x test.sh
Redirect:
The above is the detailed content of Using chmod in Linux. For more information, please follow other related articles on the PHP Chinese website!