In this blog we will see the concepts of link (symbolic and hard), what they are for and how each one works, but first we must know what a link is so:
What is a link?:
A link is a connection between a file and the actual data on the disk. Links are a very handy way to create a shortcut to an original directory.
a less technical but clearer definition could be a link is created to connect to any other file on the hard drive so we don’t have to look for the original file every time we have to use it
Once created, a link can be used in place of the target file name. It can have a unique name, and be located in any directory. Multiple symbolic links can even be created to the same target file, allowing the target to be accessed by multiple names.
There are two types of links :
- Soft Link or Symbolic links
- Hard Links
Hard Links:
hard links, can only link to files (and not directories); you cannot reference a file on a different disk or volume, and they reference the same inode as the original source. A hard link will continue to remain usable, even if the original file is removed.
- Each hard linked file is assigned the same value as the original, therefore they reference the same physical file location. Hard links more flexible and remain linked even if the original or linked files are moved throughout the file system.
- Links have actual file contents
- Removing any link, just reduces the link count, but doesn’t affect other links.
- If original file is removed then the link will still show the content of the file.
How to create a hard link
1
ln <original filename> <link name>
Soft Links:
soft link, reference a file/folder on a different disk or volume, will exist as a unusable link if the original location is deleted, soft links too reference abstract filenames and directories, and are given their own, unique inode.
- Soft Link contains the path for original file and not the contents.
- Removing soft link doesn’t affect anything but removing original file, the link becomes “dangling” link which points to nonexistent file.
- A soft link can link to a directory.
How to create a soft link
1
ln -s <original filename> <link name>
Conclusion:
To conclude we can say that the clearest difference between the types of links is:
Hard Link: Refer to the specific location of physical data.
Symbolic Link: Refer to a symbolic path indicating the abstract location of another file.
I hope this information has been to the liking of all the viewers, and RTFM :)