Linux hard and soft links details

  • 2020-05-24 06:34:18
  • OfStack

Hard and soft links in Linux

Soft links and hard links

Command ln

ln is a command to create links:

Create a hard link: ln file link

Create a soft link: ln-s file link

Hard links

Hard links (hard link) were the first way to create links on the Unix system.

By default, each file has a hard link. When you create a hard link, you actually create an additional entry point. The file is only deleted if and only if all the hard links to the file are deleted, that is, the data block is cleaned up.

Creating a hard link for a file is similar to copying a file, but the new copy is updated synchronously with the original version.

This is because all files on the Linux file system are assigned a number, called the node index number (Inode Index), to create a hard link, and inode is the same number, so it can be updated synchronously.

Two limitations of hard links:

1. Hard links cannot point to files outside of their own file system, that is, cannot cross the hard disk partition (soft links can).

2. Hard links cannot point to directories.

Soft links

Soft links (software link), also known as symbolic links (symbolic link), are analogous to shortcuts on Windows.

Deleting soft links will not affect the pointing to files; If the file is deleted and the soft link is not deleted, the link will exist but point to nothing; it is broken.

conclusion

Hard link: copy + sync

Soft links: shortcuts

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: