Hard Links and Symbolic Links, a comparison
To gain a deeper understanding of what those two things are (Hard and Symbolic Links) we’re first going to dig a little bit into the topic of inodes.
The inode is a data structure that is used to describe filesystem objects, for example a file, or a directory. Each inode contains the physical disk block location of the object’s data and different object attributes such a s the last time it was changed, modified or accessed, as well as the owner and permission data. So each one of those inodes works as a pointer telling us where in memory the different pieces of data attached to the specific node in questions information is.
What does that have to do with Hard and Symbolic Links?
While both of them point files at one another (hence the whole link part), they’re different in the way they point. Hard Links point to the file by its inode number. as such, hard links are no different than the first name of a file. When you hard link a file, they all might have different names, but they all point towards the same piece of data. Symbolic links on the other hand just point towards another file by name. It has its own special bit mode that identifies it and its contents are the name of the real original file. because it contains just this name, it doesn’t actually have to exist, or can exist on a different filesystem. If you swap the contents of the file or the entire file itself, but, keep the original human readable name of the file, the symbolic link will still work. After all, it’s just pointing towards a name rather than anything from the file that is a completely unique identifier.
So to kind of reiterate the difference between the two, symbolic links are superficial in that they don’t care about the actual data in what they’re pointing towards, they just care that something is there. Hard links on the other hand 100% depend on there being a piece of data as all of their inode-numbers under the hood are pointing towards the same place, much like a collective point by a group of people.