These are the general differences between hard links and symbolic links on a Linux system that allow convenient links to files on the filesystem.
Hard links and symbolic links are the two pointers to files or directories in a Linux file system. It is important to note that hard links cannot be used on a directory.
A hard link is a synchronized copy of a file that refers directly to the inode of a file. On the other hand, Symbolic links are shortcuts to files. They point directly to the file which refers to the inode. So what is an inode?
Inodes, Hard Links, and Symbolic Links
The inode is a database that describes the file and directory attributes such as metadata and the physical location on the hard drive in numerical format. Linux operating systems use this metadata to retrieve information about the file such as roles and permissions and the physical location of the data on the hard drive.
Hard Links
A hard link points to the file via this inode. Therefore when you change the original file details the hard link still retains its reference. Because of this:
- Hard links can only refer to files within the same volume
- Hard links cannot refer to directories
Symbolic Links
These references a directory or a file instead of its inode value. Unlike hard links, symbolic links can also reference resources across different hard disks, or volumes. Changing the symbolic link will also change the original file. Moving the original file will break the symbolic link and leave a dangling link.
That’s it for this brief explanation about these reference links in Linux.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.