What is the difference between Hard Links and Soft Links
Apart from the concept of pointers in C hardlinks and Softlinks work differently.
Every file has an inode number. This number is like an address similar to that of your house so whoever has it can go your house. So the hardlinks knows about the address and softlink only knows about the house and not the address.
Hardlink points to the inode number of the file so even if you change the name of file hardlink still has the address of the file hence will still have an access of the file. Coming to the part of Softlinks they point to the “file” rather than the address so the moment the original file is moved or renamed or deleted the softlink doesn’t work. Hardlinks work only on the same system or disks. Here we have a benefit that Softlinks can work on within multiple systems and disks. However if a old file is removed and a new files is added with the same name as previous then hardlink will fail but the softlink will still work. Thus hardlinks only worls for files and not for directories. Do remember Linux never allows users to create hardlinks associated with directories and only with files so no need of running smart. Howvever we all face miseries so to links directories one may use softlinks
Lets us simplify about hardlinks and softlinks by examples.
Step 1. Create a directory "linkf" (only for example set yours freely) Move to this new directory and create two new files named as
"sfile" and "hfile". Cat data in each file as shown in below .gif
Step 2. Create a softlink and a hardlink for each of the files above. soflink for "sfile" and hardlink for "hfile"
Step 3. Search the inode number of each link and comparing it with their source files
Step 4. If inode numbers have been found then rename the "sfile" to "sfile_new" and "hfile" to "hfile_new"
Then do a ls command and cat both links.
We observe that the color of soflinks change to red indicating missing or malfunctioning
No comments:
Post a Comment