The Linux chmod command is used to set the permissions of files or folders (hereinafter referred to as archives) on the Linux system. The following describes the usage of the command in detail.
Command Format: chmod [-cfvR] [-- help] [-- version] mode file...
The string used to set the permission for mode. The parameter format is as follows:
[Ugoa...] [[+-=] [rwxX]...] [,...]
U indicates the owner of the archive, g indicates that the owner of the archive belongs to the same group, and o indicates that the owner of the archive belongs to others. a indicates that all three belong to the same group.
+ Adds a permission,-Indicates canceling the permission, and = indicates a unique permission.
R indicates that the file can be read, w indicates that the file can be written, x (lower case) indicates that the file can be executed, and X (upper case) indicates that only when the file is a subdirectory or the file has been set to executable.
-C. If the permission of the archive has been changed, the change action is displayed.
-F if the permission of the archive cannot be changed, do not display an error message.
-V: detailed information about permission change
-R: Change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)
-- Help: displays auxiliary instructions
-- Version: displays version information.
The following use cases are described:
The system has such a file:/home/www/exam. sh
(1) set the above files to be readable by all users:
Chmod ugo + r/home/www/exam. sh
Or:
Chmod a + r/home/www/exam. sh
(2) associate the above file with another file/home/www/test. sh is set as the owner of the archive, which can be written to the same group to which the archive belongs, but not to others:
Chmod ug + w, o-w/home/www/exam. sh/home/www/test. sh
(3) set the preceding file to be executed only by the file owner:
Chmod u + x/home/www/exam. sh
(4) set all files and sub-files in the current directory to be read by anyone:
Chmod-R a + r *
In addition, you can use numbers to indicate the corresponding permissions. The syntax format is chmod abc file.
Each a, B, and c represents a number, indicating the permissions of the User, Group, and Other.
R = 4 (read), w = 2 (write), x = 1 (execute)
If the rwx attribute is required, the value is 4 + 2 + 1 = 7.
The rw-attribute is 4 + 2 = 6.
If the r-x attribute is required, the value is 4 + 1 = 5.
Articles you may be interested in
- Delete files in linux. Detailed explanation of the rm command for folder commands
- Summary of linux Command for viewing File Content
- Linux File Content statistics command wc command usage details
- Create a folder (mkdir) command in linux
- How many lines of files can be viewed in linux?
- Php clears (deletes) the files in the specified directory, and does not delete the directory folder.
- Windows cannot start the hardware device because its configuration information (in the Registry) is incomplete or damaged. (Code 19) Solution
- Linux File Creation (touch) command details