11.1 Detailed explanation of rwx permissions
11.1.1 rwx applied to files
(1) [r] stands for read: it can be read and viewed.
(2) [w] stands for writable (write): it can be modified, but it does not mean that the file can be deleted. The prerequisite for deleting a file is that the directory where the file is located has write permission before the file can be deleted.
(3) [x] represents executable (execute): can be executed.
11.1.2 rwx acts on directories
(1) [r] stands for read: it can be read and viewed.
(2) [w] stands for writable (write): you can modify, create, delete, and rename directories in the directory.
(3) [x] represents executable (execute): you can enter this directory.
11.2 Practical cases
-rw-r--r--. 1 root root 26788 4月 14 16:53 java后端生活.jpg
The first 10 characters -rw-r--r-- determine what different users can do to the file:
The first character represents the file type: file (-), directory (d), link (l);
The rest of the characters are in groups of 3 (rwx):
The first group of rw-: the permissions of the file owner are read and write, but cannot execute;
The second group r--: the permissions of users in the same group as the file owner are read-only and cannot be written or executed;
The third group r--: the permissions of other users who are not in the same group as the file owner are read-only and cannot be written or executed;
Available numbers are: r=4, w=2, x=1; thus rwx=4+2+1=7
1: The file is a hard link number, and the directory is a subdirectory tree
root: user
root:group
26788: file size (bytes), if it is a folder display 4096 bytes
April 14 16:53: Last modified date
java backend life.jpg: filename
11.3 Modify permissions
11.3.1 Basic instructions
With the chmod command, you can modify the permissions of a file or directory
11.3.2 The first way: +, -, = change permissions
u: owner
g: the group you belong to
o: others
a: everyone (sum of u, g, o)
(1) chmod u=rwx, g=rx, o=x file directory name
(2) chmod o+w file directory name
(3) chmod ax file directory name
11.3.3 The second way: changing permissions by numbers
Rules: r=4, w=2, x=1, r+w+x=7
chmod u=rwx,g=rx,o=x file directory name
Equivalent to chmod 751 file directory name
11.4 Change file owner
11.4.1 Basic introduction
chown newowner file Change the owner of the file
chown newowner:newgroup file Change the owner and group of the file
-R If it is a directory, make all sub-files and directories under it take effect recursively
11.5 Modify the group where the file is located
chgrp newgroup file Change the group of the file