Linux chmod command to modify file and folder permissions attached to an instance,
Source: Internet Author: anonymous name time: 05-01 20:46:07 [large, medium, small]
In linux, we need to use the linux chmod command to modify the permissions of a folder or file. Below I have written a few simple examples for your reference.
Syntax: chmod [who] [+ |-| =] [mode] File Name
The meaning of each option in the command is
U indicates "user", that is, the owner of a file or directory.
G indicates "group users", that is, all users with the same group ID as the file owner.
O indicates "Other (others) Users ".
A Indicates "all (all) Users ". It is the default value of the system.
The operation symbol can be:
+ Add a permission.
-Cancel a permission.
= Grant the given permission and cancel all other permissions (if any ).
Set the permissions indicated by mode to any combination of the following letters:
R readable.
W writable.
X executable.
X adds the x attribute only when the target file is executable to some users or the target file is a directory.
S sets the owner or group ID of the process to the file owner during file execution. In the format of "u + s" to set the user ID of the file, and "g + s" to set the group ID.
T save the program text to the swap device.
U has the same permissions as the file owner.
G. users in the same group have the same permissions as file owners.
O has the same permissions as other users.
Instance
How to modify the read/write attributes of a file
For example, to change the index.html file to writable and readable, execute:
Copy code
The Code is as follows:
Chmod 777 index.html
To modify the attributes of all files in the directory, perform the following operations:
Copy code
The Code is as follows:
Chmod 777 *.*
Replace the folder name with the suffix.
For example, modify the attributes of all htm files:
Copy code
The Code is as follows:
Chmod 777 *. htm
How to modify folder attributes
Change the directory/images/xiao to writable and readable and executable.
Copy code
The Code is as follows:
Chmod 777/images/xiao
Modify all folder properties in the directory
Copy code
The Code is as follows:
Chmod 777 *
Replace the folder name *.
To modify the attributes of all files, folders, and subfolders in a folder to writable, readable, and executable
Copy code
The Code is as follows:
Chmod-R 777/upload
SummaryLinuxWhat are the differences between directory and file permissions?
File: Read the file content (r), write data to the file (w), as the command execution file (x ).
Directory: Read the file name (r) in the directory and write information to the directory (add and delete the link to the index point), search for a directory (you can use this directory name as the path name to access the files and subdirectories it contains)
Specifically:
(1) users with read-only permission cannot use cd to enter the Directory: they must also have execution permission to access.
(2) users with execution permissions can access files in the directory only when they know the file name and have the read right.
(3) You must have the read and execute permissions to list the directories in ls or use the cd command to enter the directories.
(4) You have the write permission for a directory. You can create, delete, or modify any files or subdirectories in the directory, even if the file or subdirectory belongs to another user.
View directory permissions
Statement for viewing file permissions:
Enter at the terminal:
Ls-l xxx. xxx (xxx. xxx is the file name)
Then similar information will appear, mainly including:
-Rw-r --
A total of 10 digits
The first one indicates the type.
The three rw in the middle represents the owner (user)
Then the three rw-represent the group)
The last three r groups represent other people (other)
Then I will explain the nine digits below:
R indicates that the file can be read)
W indicates that the file can be written)
X indicates that the file can be executed (if it is a program)
-The permission has not been granted.
Now let's talk about modifying file permissions.
Enter at the terminal:
Chmod o w xxx. xxx
Grant other users the permission to write the file xxx. xxx.
Chmod go-rw xxx. xxx
Deletes the read and write permissions of group groups and other persons in xxx. xxx.
Where:
U stands for the owner (user)
G indicates the group in which the owner is located)
O stands for others, but not u and g (other)
A Represents all people, including u, g, and o
R indicates that the file can be read)
W indicates that the file can be written)
X indicates that the file can be executed (if it is a program)
Rwx can also be replaced by numbers.
R ------------ 4
W ----------- 2
X ------------ 1
------------- 0
Action:
Indicates adding permissions.
-Indicates the permission to be deleted.
= Indicates that it is the only permission
After everyone understands the above, we can easily understand the following common permissions:
-Rw ------- (600) only the owner has the read and write permissions.
-Rw-r -- (644) only the owner has the read and write permissions. The Group and others have only the read permissions.
-Rwx ------ (700) only the owner has the read, write, and execute permissions.
-Rwxr-xr-x (755) only the owner has the read, write, and execute permissions. The Group and others have only the read and execute permissions.
-Rwx -- x (711) only the owner has the read, write, and execute permissions. The Group and others have only the execution permissions.
-Rw-(666) everyone has the read and write permissions.
-Rwxrwxrwx (777) everyone has the permission to read and write and execute