Explanation of chmod command for modifying directory permissions
The chmod command is used to modify the permissions of a file or directory. It stands for change mode.
Syntax:
chmod [options]… permissions… filename…
常用选项:
-R: Recursively modify the permissions of files in a directory and its subdirectories.
Commonly used permissions:
u: represents the owner of the file or directory.
g: represents users in the same group as the owner of the file or directory.
o: represents other users.
a: represents all users.
Common permission symbols:
+ : Add permission.
– : Remove permission.
= : Set permission.
常用权限:
r:读取。
w:写入。
x:执行。
Example:
The example can be found in the textbook.
- Change the permissions of all users for the file file.txt to read-only by running:
chmod a-w file.txt - Change the permissions of all users for the file file.txt to read-only and recursively modify the permissions of files in its subdirectories.
- Change the owner’s permissions of file.txt to read, and remove read and write permissions for the group and others:
chmod u=r,go-rw file.txt - Set the owner and group users of directory dir to have read and write permissions, while keeping the permissions for other users unchanged:
chmod ug=rw dir
Important notes:
- There are three types of permissions: user, group, and others. Each type consists of three permissions: read, write, and execute.
- Permissions can be separated by commas or written in a continuous line.
- When changing directory permissions, using the -R option will recursively modify permissions for the directory and its subdirectories.
- When modifying permissions, symbols can be used to indicate adding, removing, and setting permissions.