This article summarizes from:
Https://www.ibm.com/developerworks/cn/linux/l-cn-hardandsymb-links/index.html#fig2
A file can be represented by:
where the filename is the name we can see.
The inode is included in the metadata (metadata), which records additional attributes of the file, such as file size, creation time, and so on.
The inode is the index node number and is the unique identifier of the file. You can use the command:
Ls-i
To view
Data blocks is a file block that records the actual contents of a file.
Here's one thing to say:
When we use rm to delete files, we simply dismiss the filename and inode references, and generally do not destroy the file data.
A hard link, however, is equivalent to adding an alias to the same inode.
So when you delete a file with RM, you can also access it through another filename if you create a hard link to the inode.
How to create a hard link:
ln Oldfile NewFile
A soft link is to create a data block that stores another filename in the data block.
So when we delete file with RM, then cat Softlink will not get the output of the actual file.
How to create a soft link:
Ln-s Oldfile NewFile
Use the ls-l command to see the number of links to the file, which appears in the second column of the output.
When you create a soft link, the number of links to the file is not added
Also, you can see the symbol, which points to the source file from the soft link file .
Using the LS-I directive, you can find that the inode number of the hard-link file is the same as the source file, and the inode number of the soft link file is different from the source file, which is the same as the above analysis.
Hard links and soft links under Linux