Detailed explanation of the difference between soft link and hard link?

Soft links and hard links are two different ways of creating file links in computer systems.

A hard link is the creation of a new filename in the file system that points to the same physical data block. In other words, hard links are multiple filenames pointing to different entries of the same file. When you create a hard link, you actually create a new directory entry in the file system that points to the same file data block. So no matter which filename you use to access the file, you will get the same content.

A symlink (also known as a symbolic link or symbolic link) is a special type of file that contains a path to another file or directory. A soft link is a shortcut pointing to a file or directory, similar to a shortcut in the Windows operating system. Unlike hard links, soft links do not directly point to the physical data block of the file, but to the path of the file. When you access a soft link, you actually find the original file or directory through the path of the soft link.

The main differences are as follows:
1. Hard links can only link to files in the same file system, while soft links can link to files in different file systems.
2. Deleting the original file has no effect on the hard link, because the hard link actually points to the entry of the file data block. Deleting the original file will invalidate the soft link, because the soft link is just a path to the file.
3. A hard link can access the same file through multiple file names, while a soft link can only access the original file through the path of the soft link.

In summary, hard links are multiple file names pointing to different entries of the same file, while soft links are a shortcut to a file or directory path. Hard links can only link to files in the same file system, while soft links can link to files in different file systems.

Guess you like

Origin blog.csdn.net/qq_45635347/article/details/132440296