1. Hard link
(Recommended tutorial:linux tutorial)
Since files under Linux pass through index nodes (inode) to identify the file. A hard link can be thought of as a pointer, a pointer to the file index node. The system does not reallocate the inode for it. Each time a hard link is added, the number of links to the file is increased by 1.
Disadvantages:
1. Links cannot be established between files in different file systems;
2. Only super users can create hard links for directories.
2. Soft links
Soft links overcome the shortcomings of hard links. There are no file system restrictions. Any user can create a symbolic link pointing to a directory. As a result, it is now more widely used, has greater flexibility, and can even link files across different machines and different networks.
Shortcomings:
Because the link file contains the path information of the original file, when the original file is moved from one directory to another directory and the link file is accessed again, the system cannot find it. Hard links do not have this defect, you can move them however you want; in addition, they require the system to allocate additional space to create new index nodes and save the path of the original file.
In actual scenarios, soft links are basically used.
The difference between the two is as follows:
Hard links cannot cross partitions, but software links can cross partitions.
A hard link points to an inode node, while a soft link creates a new inode node.
Deleting a hard link file will not delete the original file. Deleting a soft link file will delete the original file.
The above is the detailed content of What are soft links and hard links. For more information, please follow other related articles on the PHP Chinese website!