I am somewhat confused what the differences between a softlink, and a hardlink are (on unix).

It seems like a softlink is the same as a shortcut in windows or an alias on Mac OS X. (Can someone confirm this?) Softlinks can link to both directories and files.

I am uncertain of what a hardlink does or if it is useful..

Is it better to use one instead of the other?



Hard links can work only on the same file system. They are basically different names for one and the same group of data (file). I.e. if you create hard link to a file, and then you delete the original file, the link will continue to exists, and the data will be accessible trough the hard link. The disk space is released when the last hardlink is deleted. Actually, there's no difference between the original file and the hardlink you created later. They are interchangeable. After creating a hardlink, there's no more "original" and "link".

Softlinks can be used between different file systems, i.e. a link can be created in filesystem2 to link to a file/dir on filesystem1. Also, if you remove the original, the link becomes broken, as it points to a undefined location.

Yes, you can think about softlinks as a "shorcuts" in windows, but they are not exactly the same. Shortcut in windows is a file by itself, and if a program can not interpret them, it can not use them.

Here is a nicely pictured article on the topic :)

|improve this answer|||||
  • Awesome answer! Thanks for the links. The picture is especially helpful. – sixtyfootersdude Mar 8 '10 at 18:57
  • Soft link in unix like systems are also independent files (they take up an inode, they can be hard linked together, and so on), and also require interpertation (though the OS provides an API to do this). – dmckee --- ex-moderator kitten Mar 8 '10 at 20:08
  • dmckee: Symlinks are interpreted by the OS when you open or stat() them. – user1686 Mar 8 '10 at 21:36

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.