Using chmod in Linux

巴扎黑
Release: 2017-06-23 14:18:43
Original
2330 people have browsed it

Linux files are divided into three identities and four permissions.

  1. u: The owner of the file

  2. g: The group the file belongs to

  3. o : Other users

For each identity, there are four permissions, namely:

  1. r: permission to read files (read )

  2. w: Permission to write files (write)

  3. x: Permission to execute (execute)

  4. 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 changes file permissions in numerical form

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 changes file permissions in character form

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:


Finally, here is a comprehensive example. In the future, similar questions can be answered by analogy:


##chmod

u

g

o

a

+(plus)

-(minus)

=(SET)

r

w

x


##File or directory

chmod u=rwx,g+rx,o-x test.sh
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template