Soft link and hard link details
Today, we will introduce the following soft links and hard links.
I. What is inode?
To understand inode, start with file storage.
1. The file is stored on the hard disk. The minimum storage unit of the hard disk is 512 bytes, which is equivalent to 512 bytes.
2. When the Operating System reads a hard disk, it does not read multiple sectors. This is too inefficient. Instead, it reads multiple sectors consecutively at a time, that is, one "Block" should be read at a time ",
Is the minimum unit for file access. The most common size of a block is 4 kb.
3. the file data is stored in blocks. Obviously, we must also find a place to store the file metadata, such as the file creator, creation date, the file size is called inode. index Node
II. Inode number
1. Each inode has a number. The operating system uses the inode number to identify different files.
2. linux uses inode numbers instead of file names to identify files.
3. On the surface, the user opens the file through the file name. In fact, the internal process of the system is divided into three steps.
First, the system finds the inode number corresponding to the file name, and then obtains the inode information through the inode number. Finally, based on the inode information, it finds the block where the file data is located and reads the data.
3. Hard Link
Multiple File Names correspond to one inode number,
This means that you can access the same content with different file names. Modifications to the file content will affect all file names. However, deleting a file name does not affect access to another file name.
Number of hard links: There are several file names corresponding to one inode, and the number of hard links is several
Deleting a file name will reduce the number of links in the inode node by 1. When this value is reduced to 0, it indicates that no file points to this inode, and the system will reclaim this inode number, and the corresponding block area, that is, the data zone.
4. Soft link
Although the inode numbers of file A and file B are different, the content of file A is the path of file B. When reading file A, the system will automatically direct the visitor to file B. Therefore, no matter which file is opened, file B will eventually be read. In this case, file A is called the "soft link" of file B ".
This means that file A depends on file B. If file B is deleted, an error will be reported when file A is opened.
File A points to the file name of file B, instead of the inode number of file B. The number of inode links of file B does not change.