Described in the previous how to view the properties of the file in Linux, in the Linux file permissions explained in detail we introduced the Linux file three identities and four kinds of permissions, three identities were:
- U: Owner of File
- G: The group to which the file belongs
- O: Other users
For each identity, there are four different permissions, namely:
- R: Permission to read files (read)
- W: Permission to write to file (write)
- X: Execute permission (execute)
- S: Special Permissions
In the Linux file permissions explained in detail, we know that there are two ways to represent file permissions in Linux, respectively, the number and symbol representation.
chmod changing file permissions in digital form
chmod 755 test.sh
Converts 755 into character form, Rwxr-xr-x, that is, the owner of the file, The owning group and other users can read and run the test.sh file, but only the owner can write to the file themselves, that is, the other person is not authorized to modify the test.sh file. (Of course, the root user does not have this limitation, who wants to change who, this is also an experience that embodies the supremacy of root account!) )
To change the permissions of the file through the mathematical form is relatively simple, as long as the implementation of the permissions required to give the file, and then call the chmod instruction, the call form is:
chmod New Permissions File list
chmod changing file permissions as characters
chmod +x test.sh
The mathematical form can change the file of all three identities of four permissions at a time, and the character form is more flexible, you can give a certain identity of a permission to set a separate, such as the above instruction is to give three kinds of identities to give execution permissions, you can also separate settings:
chmod u+x test.sh Only add executable permissions to the owner
chmod g+x test.sh Only add executable permissions to group identities
chmod o+x test.sh Only add executable permissions to other people
All of the above three directives are combined to be equivalent to the one above, which is the ability to turn on executable permissions for all identities, and you can do the following as well:
chmod a+x test.sh
The A here represents all of the 3 identities!
If you want to remove a certain permission from an identity, you only need to change the + to- can, for example, remove the executable permission for someone else's identity:
chmod o-x test.sh
For read, write and other permissions, follow the above way to practice more, chmod through the character of the file permissions to change the operation see the following table:
chmod |
U G O A |
+ (plus) -(minus) = (set) |
R W X |
File or directory |
Finally, a comprehensive example, after a similar problem extrapolate can:
chmod u=rwx,g+rx,o-x test.sh
Transferred from: http://www.letuknowit.com/topics/20120408/change-file-attributes-on-linux.html/