Summary of how to use the chmod command in Linux

The chmod command is used to change the permissions of a file or directory

It allows users to control who can read, write and execute files.

Permissions consist of three components, which are owner permissions, group permissions, and other user permissions.
u (owner), g (group), o (other users), a (all users)
Note: a refers to all users, that is to say, ugo is included

Use the plus (+), minus (-), and equal (=) signs to set permissions.

For example: chmod u+rwx,g=rx,o=r filename the owner of the file is set to read, write and execute permissions, the group to which it belongs is set to read and execute permissions, and other users are set to read-only permissions.


The basic syntax of the chmod command is as follows:

chmod [options]... permissions file...

The commonly used syntax is as follows:
chmod [{ugoa}{+-=}{rwx}] filename;

There are two ways to express the permissions of files or directories. In addition to using rwx, you can also use 421

r (read) permission is represented by the number 4
w (write) permission is represented by the number 2
x (execute) permission is represented by the number 1
- (no permission) is represented by the number 0

In the digital mode, the authority of each group is represented by a three-digit number, representing the authority of the owner, the authority of the group to which it belongs, and the authority of other users.

For example: chmod 755 filename
set the owner of the file to read, write and execute permissions, while the group and other users only have read and execute permissions.

In addition to basic file permissions, the chmod command can take some additional options, such as recursively changing file permissions in a directory and its subdirectories ( -R option).

All in all, the chmod command allows users to flexibly set the permissions of files or directories as needed to control access and operations on files.



Example study:

1) chmod g+w testfile
Add a w write permission to the group to which the testfile belongs

2) chmod a+x testfile== chmod +x testfile
Add execution permissions to all users of the testfile file

3) chmod -R 777 testfile
Modify the testfile directory and all the files in the directory to say that the user has all permissions

4) chmod a=rwx testfile== chmod 777 testfile
All users of the testfile file have full permissions

Please add a picture description



The role of rwx permissions for files and directories

insert image description here

Guess you like

Origin blog.csdn.net/qq_42595610/article/details/131894565