0

I learned that unlike HardLink, SoftLink acutally store information about original file in HDD. And I made test1(original file) and test2(softlink of test1) And then I mv(renamed) test1 to test3 So the softlink test2-->test1 turned red and deactivated. I thought Linking uses Inode number and test1 and test3 had same Inode number but the SoftLink doesn't worked.

Here is the Question : what information does softlink required to activate Link??

4

A soft link, also known as symbolic link, tracks a file by its name, not its inode. Because of this, the file that you link to can be located anywhere, not just on the same filesystem (unlike hard links); another feature is that soft links can point to other soft links, up to a maximum. The soft link is essentially a special file that stores the target path inside, but Linux knows about this type of file and reads the "inside" path and tries to access that file instead, using the permissions on the target file. Programs can ask Linux to not follow the link but instead give information about the file itself (which is how ls can show you what the target path is); however, most programs only care about where the link points to.

So to answer your question, a soft link contains all the information that is needed inside of itself. The operating system then does all the work of tracking where the link points to.

0

Soft links are only linked to name of the file and not to the inode number. If the original file is renamed, the soft link is broken, and the link now doesn't know where it is pointing to. Posting this picture from one of the answers (which I don't remember, I saved this picture in my phone long ago) : enter image description here

If the original file is renamed, my-soft-link will point to a file name which no longer exists and hence will turn red as the link or the pointer will be broken. In such a case, my-soft-link would be similar to a dangling pointer. It points to a file which does not exist.

On the other hand, there is no such problem in hard links because hard links point directly to the inode number. So if the original file is renamed, my-hard-link will not become a dangling pointer.

So in order to reactivate your symbolic link, you can update your symbolic link by making it point to the renamed file.

ln -sfn test3 test2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.