Link is a mechanism of creating a shortcut to the original file or directory which contains information about its files or directories.
What is Soft link?
A symbolic link, also known as symlink or soft link, is a special type of file that points to source file or directory in Linux.
It is like a shortcut in Windows which contains the path of the original file and not the contents.
In general, Symbolic links are used to link libraries and log files & folders on mounted NFS (Network File System) shares.
Please refer the following article to remove/delete Symbolic Links in Linux
What is Hard link?
Hard link is a mirror copy of the original file. Deleting the original file will not impact anything, because the hard link file, will act as a mirror copy of the original file.
Why we need to Create a link file instead of Copying them?
Creating a Link file is specifically useful when the same file is kept in multiple location with updated contents.
Copying a file to another location, will merely copy the content of the file and it will never get updated from the source file.
The contents of the file may vary from time to time.
Difference between Soft link vs Hard link
I have included possible difference between the soft link and hard link in the below table.
|S.No||Soft Link||Hard Link|
|1||Soft link is similar to the file shortcut in Windows.||Hard link is a mirror copy of the original file.|
|2||Soft link can be referred as Symbolic link or symlink.||Hard link has no other names.|
|3||Changes in both the files will reflect simultaneously.||It is like a soft link.|
|4||Soft links can be created on different file systems.||Hard link can only be created on the same file system.|
|5||Soft link can be created to files and directories||Only files can be linked|
|6||It has different inode number and file permissions compared to the original file.||It has the same inode number and file permissions.|
|7||It contains the path of the original file and not the contents.||It contains the actual contents of the original file.|
|8||When the original file is removed, the link will be inaccessible because it points to a non-existent file. This is called the hanging link.||Nothing happens when the original file is removed.|
|9||Soft link can be created using the following command (||Hard link can be created using the following command (|
|10||Soft link file contains a special symbol “l” in the file permission field.||There is no special symbol as such.|
|11||Soft link file can be found using the following command (||Hard link file can be found using the following command (|
|12||A broken soft link can be found using the following command (||Not applicable|
This article portrays the difference between Soft & Hard link in general.
Do share with others, if found useful!!!