What is the difference between a Hard link and a Soft Link?
In file System, two types of links are used to associate a file with one or more file names, and these links are Hard link and Soft link. In this topic, we will discuss the differences between both of them. Let’s start with the introduction of Hard link.
What is a Hard link?
The hard link is a technique for directly joining two files within the same system. A file is identified by its index node (inode) number when using hard links. Using hard links on directories is impossible since they point to inodes.
In order to build a hard link, the "ln" command is used. This command produces a new file on the command link that is used to refer to the original file. The content and number of index nodes (inodes) are identical in both the hard-linked and original files. For this reason, the owner and permissions of both files are the same.
This would have an impact on the hard-linked file if we deleted the original. As a result, even after the original file is deleted, the hard-linked file will still be present. Hard connections can only be linked to their partition and use less memory space. Relative paths are prohibited when dealing with hard links.
What is a Soft Link?
Numerous references can be used to reach a file. A soft link is one where all these point to the same file. Stated differently, a soft link is a file reference that is referred to by its file name. As a result, an alias or different path to the original file is what a soft link is. Soft links do not use the index node (inode) number. Because soft links include the name of the target file, they are also known as symbolic links.
When a file is reached using a soft link, the path specified in the soft link's topic is used to reroute the link to the destination file.
What is the difference between a Hard link and a Soft link?
The following table outlines the critical distinctions between hard links and soft links.
Soft link | Hard link |
1. A pointer to the pathname of the file. | 1. Another directory entry that points to the identical inode. |
2. It has its inode and is a distinct file. | 2. Alludes to the same file going by a new name. |
3. Little in dimensions. | 3. Identical in size to the original file. |
4. Possesses a unique set of authorizations. | 4. Has the same permissions as the original file. |
5. Able to point to a directory or file. | 5. Not directories, only points to files. |
6. The link is broken if the original file is removed or relocated. | 6. Data is still accessible even if the original file is moved or removed. |
7. Made with the help of the ln-s command. | 7. Created with the ln command. |
8. Able to join files from several file systems together. | 8. Restricted to using the same file system. |
9. On specific platforms, the link has an arrow or appears in a different colour. | 9. Appears as a separate file entry with a distinct name. |
10. Contains the target file's path. | 10. Links directly to the original file's inode. |
11. Able to connect to files that are not there and folders. | 11. Only pre-existing files can be linked; directories cannot. |
12. It can be configured with absolute and relative paths. | 12. Firmly linked to the original path of the file. |
13. Involves two inodes—one for the original file and one for the link. | 13. Has the same inode as the original file. |
14. The symbolic connection remains intact after the original file is deleted. | 14. The hard link retains the data even if the original file is removed. |
15. It is simpler to distinguish from the original file and recognize it as links. | 15. their shared inode makes it more challenging to differentiate from the original file. |
16. A copied soft link creates a new link that points back to the original destination. | 16. Create a separate file with the properties and data copied. |
17. Useful for transferring files between file systems and folders. | 17. Ideal for establishing several references in a single file system. |
18. Able to create directory links. | 18. Does not allow directory linking. |
19. Supported as shortcuts in Windows. | 19. Exists in specific Windows subsystems but is not supported similarly. |
20. The soft link remains intact even if the original file's name is changed. | 20. Since they are the same file, changing the original file's name also modifies the hard link's name. |
21. Separate from the file system. | 21. Depending on the inode structure of the file system, |
22. Allows the route to be specified when creating a link. | 22. Requires the file's name to create a direct link to it. |
23. Locate the target file by following the symbolic path. | 23. Directly resolves to the original file. |
Conclusion
A soft link is an alternate path that accesses the target file without referring to an inode, whereas a hard link is an alternate path to the original file that uses an inode to do so. This is the main distinction that you should be aware of.