Linux symbolic links (soft) and hard links

On Linux, it is possible to create links to existing file. These links can be either symbolic links or hard links. Each of them having advantages and drawbacks. In this small post, we will see the differences between the two kinds of links and how to use them.

Hard Link

An hard link refers directly to the physical location of another file (an inode to be precise).

A hard link has some limitations: it cannot refer to a directory and cannot cross file system boundaries. It means that you can only create hard links to the same file system where the hard link is located.

When the source of the link is moved or removed, the hard link still refer to the source.

Symbolic link are created with the ln command. For instance, to create a link to source_file:

ln source_file link

Symbolic Link

A symbolic link refers to a symbolic path indicating the location of the source file. You can see it as a link to a path (itself refering to an inode).

A symbolic link is less limited. It can refer to a directory and can cross file system boundaries.

However, when the source of the link is moved or removed, the symbolic link is not updated.

Symbolic link are created with the ln command. For instance, to create a symbolic link to source_file:

ln -s source_file link

Deletion

The deletion of a link (hard or symbolic) can be achieved with the rm or unlink commands:

rm link
unlink link

Conclusion

And that's it!

Symbolic and hard links are very useful tools and are very easy to use.

I hope that this blog post helped you understand a little better the differences between the two types of links and how to use them.

Related articles

  • Links of the Week
  • Java Links of the week
  • Links of the week (April 20)
  • Hardware Guide : The Hard Disks
  • NIO.2 : The new Path API in Java 7
  • Changing root hard disk on Gentoo with LVM and Grub2
  • Comments

    Comments powered by Disqus