Hard link and Soft link

What is the difference between hard link and soft link?

Questions by rahul1st

Editorial / Best Answer

BijaylaxmiMohapatra  

  • Member Since Nov-2008 | Nov 29th, 2008


Hard Link
when a file is copied, both the original and copy occupy separate space on the disk.
unix allows a file to have more than one name and yet maintain a single copy on the disk. The file is then said to have more than one link or name, but all have the same inode number. This is called hard link. All attributes are identical any modification or change in one file is automatically available in the linked file. It provides some protection against accidental deletion. Let there be a file named restore.sh. You need to create another file which provides as backup to the original file. By creating a link, you create a backup.
unix command used to create hard link >>ln- backup.sh restore.sh

Soft Link
It doesn't have the file's content but simply provids pathname of that automatically has the contents. This is called as softlink. but incase the original file is deleted we can't get the file's content from the linked file, coz, it just provides the path name of the file. This is also known as symbolic link. Windows shortcuts are more like symbolic links. The original file and the linked files have different inode nos.
Unix command used to create soft link>>ln-s

Showing Answers 1 - 9 of 9 Answers

jmagill

  • Aug 21st, 2008
 

The data part of a file is associated with something called an 'inode'. When more than one filename references the same inode number; these files are said to be 'hard linked' together.
On the other hand, there's a special file type whose data part carries a path to another file. Since it is a special file, the OS recognizes the data as a path, and redirects opens, reads, and writes so that, instead of accessing the data within the special file, they access the data in the file named by the data in the special file. This special file is called a 'symbolic link' or a 'soft link'.

Hard Link
when a file is copied, both the original and copy occupy separate space on the disk.
unix allows a file to have more than one name and yet maintain a single copy on the disk. The file is then said to have more than one link or name, but all have the same inode number. This is called hard link. All attributes are identical any modification or change in one file is automatically available in the linked file. It provides some protection against accidental deletion. Let there be a file named restore.sh. You need to create another file which provides as backup to the original file. By creating a link, you create a backup.
unix command used to create hard link >>ln- backup.sh restore.sh

Soft Link
It doesn't have the file's content but simply provids pathname of that automatically has the contents. This is called as softlink. but incase the original file is deleted we can't get the file's content from the linked file, coz, it just provides the path name of the file. This is also known as symbolic link. Windows shortcuts are more like symbolic links. The original file and the linked files have different inode nos.
Unix command used to create soft link>>ln-s

swad_bittu

  • Dec 21st, 2010
 

Hard Link
1. Both the file and link have same inode numbers.
2. If the original file is deleted, link also deleted .
3. Cannot be used to link file on another file system.
4. Cannot be used to link directories.

Soft Link
1. Both the file and link have different inode numbers.
2. If the original file is deleted, the soft link remains there as invalid link.
3. It can be used to link file on another file system.
4. It can be used to link directories.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions