Difference between Softlink and Hardlink
What is hard Link & Soft Link in Linux?
Hard Link Soft Link
1. Inode no 1.Inode No
2. Permission Same 2.Permission Different
3. Size 3.Size
4. Remains even delete the Original file 4. Removed/Useless after delete the Original file
Hard link (HL): When we create a file or directory it’s get a inode Number which is unique in our HDD and assigned by our filesystem same Inode used when we create a hard link of any file, we can create multiple HL of any file but content will be reflect same on all Hard link ,it works within the same partition if we will delete our Original file still we can access our file with another Hard link.
Note: Hard link works only for Files not for directory and works within same partition .
Original file1 Hardlink1 Hardlink2 original file Softlink1 Softlink2
File1 Inode: 123
File1 Inode: 123
#vim file1 (create a test file and write some content inside )
#ln file1 /root/newfile (for create the Hardlink of any file )
#ll ( can see total links of file )
Note : As above there is two links of file one is original and another one is HL we create .
#find –samefile /root/hardlinkname ( for see the all hardlinks location )
#ls –i filename ( for check the inode no of any file )
#cat /root/newfile ( for check contents it should same in all hardlinks )
#cat /root/test/file1 (for check contents it should same in all hardlinks)
Softlink : Softlink also known as symbolic link ,it works similar as windows shortcut option which redirect us to original file same in Linux by softlink ,we can create softlink of file or directory on different partitions, it’s got different inode number then original if original file deleted then softlink also not workable .
#ls –s /path/filename /path/linkname ( for create the softlink )
Here we have created the Soft&Hard link and verify the content also