1. Hard Links: File aliases
With the previous Linux ext2 file system, we know that in the block of the directory file, the file name and the corresponding inode are stored in the directory.
Multiple filenames can be mapped to the same inode,
Create a new file name to link to an inode number, which is a hard link.
As you can see, a hard link simply creates a new file name and associates it with an existing one.
At this point, the block in the directory has written a file name/inode data
Therefore, hard links do not increase the consumption of inode and block.
2. Soft Links: Similar to shortcuts in Windows
The essence of a soft link is that a separate file is created , and when the file is read, it points to the file name of the file it is linked to. A feature similar to redirection.
A soft link creates a new file, so it consumes inode and block .
3. Comparison of hard links and soft links
1) Hard links more secure, multiple file names corresponding to an inode, if you delete files, as long as there are other filenames corresponding to the Inode file, the file will not be deleted,
At this point, just reduce the number of connections to the file by 1, and when the number of connections is 0 o'clock, the file is actually deleted .
Hard links do not consume inode and block
hard links cannot be linked to directories.
2) Soft Link
Soft links are flexible and can be linked to files and directories .
But it consumes inode and block, but this space is nothing.
If the destination file is deleted, reading the linked file will fail.
Linux hard links and soft links