This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021.
One of the best things about Linux is its multi-tasking environment. And in order to let each user have more confidential file number, so the file authority management becomes very important. Linux classifies file access identities into owner, group, and others, and each of the three identities has read, write, and execute permissions.
File attributes
Run the ls command to view the properties of the files in the current directory:
ird@ird-xps13:~$ls-alh total usage 196K drwxr-xr-x 32 ird irD 4.0K 10月 26 11:34. drwxr-xr-x 4 root root 4.0k 10月 25 03:31.. Drwxrwxr-x 4 ird ird 4.0k 10月 26 10:58. audacity-data-rw ------- 1 ird ird 5.5K 10月 26 11:18. bash_history-rw-r --r-- 1 Ird ird 220 10月 25 03:31.bash_logout -rw-r--r-- 1 ird irD 3.7K 10月 25 03:31.bashrc DRWX ------ 25 ird ird 4.0k 10月 26 Cache DRWX ------ 30 ird ird 4.0K 10/26 10:51.config drwxrwxr-x 4 ird ird 4.0k 10/25 20:19. cxoffice DRWX ------ 3 irD IRD 4.0k 10月 25 11:35. dbus...Copy the code
File properties are divided into seven sections, from left to right: file type and permission, number of connections, owner, group, file size, modification date, and file name.
1. File type and permission:
Drwxrwxr-x = d RWX RWX r-x = d RWX
• If the value is [d], the value is a directory, for example, the line in which the file name is.config.
• [-] indicates a file, for example,.bash_history.
• If [l], it is a link file.
• If [b] represents the interface device (random access device) that can be stored in the device file.
• If [c], it represents the serial port device in the device file, such as keyboard, mouse (one-time reader device).
The remaining three parts represent the permissions that the file owner can have, the permissions to join this group account, and the permissions of other accounts that are not included in this group. RWX indicates: [r] indicates read, [w] indicates write, and [x] indicates execute. If there is no permission, use a minus sign [-].
2. Connection number (I-node) :
Each file records its permissions and properties to the i-Node of the file system, but the directory tree we use uses a file name to record them, so each file name is linked to an I-Node. This property records how many different file names are linked to the same I-Node number.
3. Owner: Indicates the owner account of the file (or directory).
4 groups:
On Linux, your account is added to one or more groups. For example, p1, p2, and p3 belong to group People. Assume that a file belongs to group People and the file permission is -rwxrwx–. Then p1, P2, and P3 have read, write, and execute permissions on the file (see group permissions). However, if the account is not a member of the People group, it does not have any permissions on this file.
5. File capacity: specifies the file capacity. The default unit is bytes.
6. Modification date: indicates the creation or last modification date of the file.
7. File name: If it is a hidden file, use. At the beginning.
Change file properties and permissions
Related commands are as follows: CHGRP: changes the owning group of a file, chown: changes the owner of a file, and chmod: changes the permission of a file.
1. CHGRP (Change Group) :
Grammar:
chgrp [-R] dirname/filename ... Options and parameters: -r: to make continuous changes recursively, that is, to update all files and directories in the subdirectory to become the group meaning. Often used to change all the files in a directory.Copy the code
For example, change the group of the file examples.desktop to root:
root@ird-xps13:/home/ird# ls -lhTotal dosage 48K-RW-r --r-- 1 IRD IRD 8.8K 10月 25 03:31 examples. Desktop... root@ird-xps13:/home/ird# chgrp root examples.desktop
root@ird-xps13:/home/ird# ls -lhTotal dosage 48K-rw-r --r-- 1 irD root 8.8K 10月 25 03:31 examples. Desktop...Copy the code
Chown (change owner) :
Chown can change file owners as well as groups! The syntax is as follows:
Chown [-r] Account name File or directory CHown [-r] Account name: group name File or directory Options and parameters: -r: continuous changes are made recursively, that is, changes are made with all files in the sub-directoryCopy the code
Example: change the owner of examples. Desktop to root:
root@ird-xps13:/home/ird# ls-lh total usage 48K-rw-r --r-- 1 ird ird 8.8K oct 25 03:31 examples. Desktop... root@ird-xps13:/home/ird# chown root examples.desktop root@ird-xps13:/home/ird# ls-lh Total 48K-rw-r --r-- 1 root ird 8.8K 10月 25 03:31 examples. Desktop...Copy the code
Example: Change the owner and group of examples. Desktop to root:
root@ird-xps13:/home/ird# chown root:root examples.desktop root@ird-xps13:/home/ird# ls-lh Total 48K-rw-r --r-- 1 root Root 8.8k 10月 25 03:31 examples. Desktop...Copy the code
3. The chmod:
There are two ways to change permissions: numeric type and symbolic type.
• Numeric type changes file permissions:
RWX stands for 421, for example, when the permission is [-rwxrwx–], the score is:
owner = rwx = 4+2+1 = 7
group = rwx = 4+2+1 = 7
Others = – = 0+0+0 = 0
Number type change permission syntax:
Chmod [-r] xyz file or directory options and arguments: xyz: is the permission attribute of the numeric type just mentioned, and is the sum of the value of the RWX attribute. -r: makes continuous changes recursively, that is, changes along with all files in the subdirectoryCopy the code
Example: enable the examples. Desktop permissions:
root@ird-xps13:/home/ird# ls-lh total usage 48k-rw-r --r-- 1 root root 8.8k oct 25 03:31 examples. Desktop... root@ird-xps13:/home/ird# chmod 777 examples.desktop root@ird-xps13:/home/ird# ls-lh Total usage 48K - RWXRWXRWX 1 root root 8.8K 10月 25 03:31 examples. Desktop...Copy the code
• Symbol type changes file permissions
In the rule of changing the permission of symbol type, we use U, G, O to represent the permissions of user, group and owner. In addition, a stands for all, the identity of the whole.
For example, change the permission to the examples. Desktop file to -rw-r–r– :
root@ird-xps13:/home/ird# chmod u=rw,go=r examples.desktop root@ird-xps13:/home/ird# ls-lh Total 48K-rw-r --r-- 1 root Root 8.8k 10月 25 03:31 examples. Desktop...Copy the code
For example, add the write permission to the examples.desktop file:
root@ird-xps13:/home/ird# chmod a+w examples.desktop root@ird-xps13:/home/ird# ls-lh Total 48K-rw-RW-rw-1 root root 8.8K 10月 25 03:31 examples. Desktop...Copy the code
Meaning of Permission
1. For files, RWX stands for:
• R (read) : reads the actual content of the file, such as the text of a text file.
• W (write) : you can edit, add, or modify the content of a file (but not delete the file).
• x (eXecute) : this file has permissions that can be executed by the system (similar to exe and bat in Windows).
2. For directories, RWX stands for:
• R (Read contents in Directory) :
Permission to read a directory structure list, so when you have permission to read (r) a directory, it means you can query the file name data in that directory. So you can use the ls command to display a list of the contents of the directory.
• W (Modify contents of Directory) :
Indicates that you have the permission to change the directory structure list, that is, you can delete the directory or the files under it.
• X (Access Directory)
The x of the directory indicates whether the user can enter the directory and become a working directory. The so-called working directory is the directory that you are currently in.