Difference between hard link and symbolic link

Difference between hard link and symbolic link

No hay texto alternativo para esta imagen


Hard Link Definition

Hard links directly link two files on the same file system and use the file's inode number for identification. Hard links cannot be implemented on directories (since they point to inode). When the " ln " command is used to generate a hard link, it creates another file on the command line that can be used to refer to the original file. Both the original and the generated file have the same inode and content; Therefore, they will have the same permissions and the same owner.

Deleting the original file does not affect the linked file, and a linked file will remain. The inode has a counter, to calculate the number of hard links to itself. When the counter returns a value of 0, the inode is flushed. Whenever you make changes to the hard link, it will be mimicked in the original file

Symbolic Link Definition

Symbolic links are usually an alternate path (or alias) to the original file; these are also known as symbolic links. Includes the name of the "target file" of the link, a flag that specifies that it is a soft link. When a file is accessed, the soft link redirects it to the destination file via the path written in the subject of the soft link.

These are very useful in the case of Windows OS, where the soft link behaves like shortcuts. The creation and removal of soft links do not affect the original file. If the target file is deleted, the soft link hangs, which means it points nowhere and generates an error message when the target file is accessed. Soft links do not use inode number, unlike hard link. An absolute or relative path could be a part of symbolic links.

?Key Differences Between Hard Link and Symbolic Link

  1. A hard link is an additional name of the original file that refers to the inode to access the destination file. In contrast, the soft link is distinct from the original file and is an alias to the original file but does not use inode.
  2. On Linux, the command used for hard link creation is " ln ". As against, the command used for a soft link is " ln -s ".The hard link has the same inode number different from the soft link, where the target file and its soft link have a different inode number.

3.???Hard links are restricted to their own partitions, but soft links can cover different file systems.

4.???Hard link performance is better than soft link in some cases.

5.???Relative path and absolute path are allowed in soft links. In contrast, the relative path is not allowed on a hard link


Conclusion

A hard link requires no additional space and the mesh resolves faster, but changes made to a hard link are reflected in the original file. On the other hand, the soft link needs additional space, but any change to the soft link does not affect the original file. Soft links are allowed to directories unlike Hard link.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了