ArticleDirectory
- Parameters
- Description
- Option
- Example
- Tips
Modify file permissions
Chmod [Options]Who operator permission file-list(Symbol Mode)
Chmod [Options]Mode file-list(Absolute Mode)
Parameters
File-list YesChmodThe name or directory path of the file to be modified.
Description
In Linux, there are two methods to change permissions:
First, use the symbolic mode. For example, chmod A + X file. Here, a represents all users, + represents adding permissions, and X represents executing permissions.
Type 2: Use absolute mode, for example, chmod 777 file, to add readable and writable executable permissions to all users. The three values correspond to three user types respectively.
Symbol Mode
WhoUser Type
Who |
User Type |
Meaning |
U |
User |
File owner |
G |
Other |
Group associated with the file |
O |
Other |
All other users |
A |
All |
Equivalent to Ugo, all users |
OperatorOperator
Operator |
Meaning |
+ |
Add permissions for the specified user type |
- |
Deletes a permission for a specified user type. |
= |
Set or reset permissions for a specified user type |
PermissionMode
permission |
meaning |
meaning of the file |
meaning of directories |
r |
set read permission |
you can view the file content |
you can list contents in a directory |
W |
set write permission |
you can modify the file content |
you can create or delete files in the directory |
x |
set the execution permission |
Executable File |
you can enter the directory |
We can see from the above why R and X are often set together in the directory permission.
Because you must enter the directory to read the content
Absolute Mode
Typical examples of absolute Mode
Model |
Meaning |
777 |
All users have read, write, and execute permissions on files. |
755 |
The file owner has the read, write, and execute permissions on the file. group users and other users must have the read and execute permissions on the file. |
711 |
The file owner has read, write, and execution permissions on the file. group users and other users have execution permissions on the file. |
644 |
The file owner can read and write files. group users and other users can read files. |
640 |
The file owner can read and write files. group users can read files. Other users cannot access files. |
Option
-C: display the modification process information
-F force Modify permissions
-R: recursively modify directory permissions
-V: displays the modified information.
Example Chmod U + x
$Ls-L temp-RW-r --1Siu0January10 13:50TEMP $ChmodU +X temp $Ls-L temp-Rwxr -- r --1Siu0January10 13:50Temp
List the file details. You can see that-RW-r -- excludes the first digit. Each three digits in the end represent a user type, and-indicates no setting.
Add the execution permission to the file owner.
Chmod ug + x
$Ls-L temp-Rwxr -- r --1Siu0January10 13:50TEMP $ChmodUg =Rwx TEMP $Ls-L temp-Rwxrwxr --1Siu0January10 13:50Temp
Add execution permissions to the file owner and group users
Chmod g-x
$Ls-L temp-Rwxrwxr --1Siu0January10 13:50TEMP $ChmodG-X temp $Ls-L temp-Rwxrw-r --1Siu0January10 13:50Temp
Group users minus execution Permissions
Chmod 777
$Ls-L temp-Rwxrw-r --1Siu0January10 13:50TEMP $Chmod 777TEMP $Ls-L temp-Rwxrwxrwx1Siu0January10 13:50Temp
Add readable and writable executable permissions to all users
Chmod 755
$Ls-L temp-Rwxrwxrwx1Siu0January10 13:50TEMP $Chmod 755TEMP $Ls-L temp-Rwxr-XR-x1Siu0January10 13:50Temp
Add read, write, and execution permissions to the owner, and add read and execution permissions to group users and other users.
Chmod-RV 755
$Ls-L total usage4Drwxr-XR-x2Siu4096January10 13:57 Dir$Chmod-RV755 Dir"Dir"The permission mode of is 0755 (rwxr-XR-x)
Recursively add permissions to folders and display the permission adding information
Tips
1. the folder must have the execution permission before it can be read and written.
2. In addition to the above basic user permissions, there are settings such as setuid, setgid, and sticky bit, which are somewhat advanced. Here are concise notes