Before using the chmod command, learn how to view the permissions of a file or directory
For example: To view the detailed properties of the directory/etc and file/etc/password, you can use the LS command we described earlier
650) this.width=650; "style=" float:left; "src=" http://s3.51cto.com/wyfs02/M01/79/24/ Wkiom1akdqpx2onxaaa3pzmoxjc443.jpg "title=" 2016-01-04_140757.jpg "alt=" Wkiom1akdqpx2onxaaa3pzmoxjc443.jpg "/>
, the fields 3 and 4 represent the owners and groups of the file or directory, in this case the directory/etc and the file/etc/passwd are both root and root, and the data in the 1th field represents the access rights of the file or directory, such as "Drwxr-x-r-x" and "- rw-r--r--"The data of the 1th field is divided into four parts, representing the following meanings
1th character: Indicates the type of the file, D (directory), B (block device file), C (character device file),-(normal file), letter L = (linked file), etc.
2nd to 4th character: represents the owner of the file's access rights to it
5th to 7th character: represents the access rights of individual members within the group of the file to which the user is a member
8th to 10th character: represents the access rights of other users to it
where R, W, and x represent read, write, and Execute permissions, and R, W, and X can also be represented by octal digits 4, 2, and 1
command Format : chmod has two writing formats
chmod [ugoa][+-=][rwx] File or directory
chmod [nnn] File or directory
Command function:
Change the read, write, and execute permissions for a file or directory
Common options:
-R recursively modifies the permissions of all files and subdirectories in the directory at the same time
Format Explanation:
format one: chmod [ugoa][+-=][rwx] file or directory
[Ugoa] where U is the primary user, G represents the group user, O represents the other user, a means all users
[+-=] where + represents increased permissions,-represents reduced permissions, = indicates that only the corresponding permissions are set
[rwx] where R represents Read permission, W represents write permission, X represents execute
Format two: chmod nnn file or directory
The nnn in format two is represented by the octal number, the first n represents the owner's permission, the second n represents the permission of the group, and the second n represents the permissions of the other user.
Common examples:
Example one: Create file, default file permissions are-rwxr--r--, now requires the owner of the file write permission to remove, while the group of users have read and write permissions, and let other users have full permissions
Format one command: chmod u-w,g+w,o+wx file
Format two command: chmod 567 file
Description: First read the current file permissions, is the main user has rwx that is read, write, execute permissions, belong to the group of users have Read permissions, other users have Read permissions. In the form of a method is for the owner of the user on the existing permissions on the basis of subtracting the write permission, for the group of users on the existing permissions to add write permissions and other users on the existing permissions to add read and write permissions; format Two method is directly to the main user read and Execute permission with 5 (r+x, equivalent to 4+1), The permission to read and write to a group of users is represented by 6 (r+w, equivalent to 4+2), and 7 for other user's ownership (r+w+x, equivalent to 4+2+1)
Example two: Changing the permissions of all directories and files within dir and directory dir to 777
Command: chmod-r 777 dir
This article is from the "Shiyu" blog, make sure to keep this source http://928004321.blog.51cto.com/10707688/1731359