In modern computing, hard links and soft (symbolic) links are both used to refer to various files within a hard drive – but that's about the similarities end. In this article, not only will we clarify the key differences between hard and soft links, but we'll provide relevant use cases for each one.
Hard Links
A hard link provides a quick reference to a file's inode. Since the inode contains a small database that holds specific file and directory attributes, including metadata and the actual, physical location of the file on the drive, the file itself be modified without destroying the hard link. Essentially, a hard link provides a synchronized connection to a file that exists elsewhere on your drive.
However, it's important to note that the hard link doesn't actually reference the original file – only the inode. As a result, hard links cannot be made to complete directories. They can only be connected to single files. However, individual files can be moved around the hard drive, including into new directories, without destroying the hard link. This is because the original file's inode, where the hard link is pointing, is still intact. It's only when the file is replaced entirely that the inode and, as a result, the hard link, will be destroyed.
Most users will find hard links most useful when used to maintain multiple file snapshots for the purposes of data backup. In this scenario, the different copies- or snapshots- all exist as separate hard links. By eliminating the need to make multiple backups of a complete file, users can reduce their disk space usage by hard linking all the copies.
Additionally, hard links can only be created for files that exist on the same volume and within the same file system. If this can't be achieved, a soft link will be required.
Soft Links
In contrast, soft links, also called symbolic links, simply point to a file (or directory) on a hard drive. While hard links point to a file inode that exists at a specific physical location on the hard drive, the soft link actually points to the file itself. If the file is renamed, moved into a different folder, or deleted entirely, the soft link will be rendered incomplete. This type of soft link is known as a dangling link.
When used in modern computing, soft links have several uses:
Although hard links can be used with directories or across different file systems, soft links do not share these limitations. This makes them the ideal choice when linking to a directory or when utilizing multiple file systems.
Hard Links vs. Soft Links
Now that you have a better understanding of hard and soft links, including the key similarities and differences between the two, you can begin using them to meet your computing needs. The most important point to remember is that hard links reference physical addresses on your hard drive. Soft links, on the other hand, are essentially shortcuts to specific files or directories.
You may read more about hard and soft links in Wikipedia: Hard link and Symbolic link.