Copy vs Hard Link vs Soft (Symbolic) Link

Copy vs Hard Link vs Soft LinkI was trying hard to understand the meaning of links in the Linux world. Based on what I have read, there are two types of links – symbolic (soft) link and hard links. Soft links are pointers to a file while hard links are like linked copies of a file. Wait. Did I just write copy? Confusing right? Why bother doing hard links when you can just copy and paste files from one directory to another? Don’t worry I was also confused about this topic before but a quick Google search gave me a clear answer from an Arch Linux community member Dusty. He stated that in:

Copy:

  • You have two different versions of the file.
  • If you edit one, the other one stays the same.
  • If you delete one, the other one stays there, but it may not be identical if it was edited.
  • Twice as much disk space used (two different files).

Hard Link:

  • You have one file with two different filenames.
  • If you edit one, it gets edited in all filename locations.
  • If you delete one, it still exists in other places.
  • Only one file on disk.

Soft Link:

  • You have one file with one filename and a pointer to that file with the other filename.
  • If you edit the link, its really editing the original file.
  • If you delete the file, the link is broken.
  • If you remove the link, the file stays in place.
  • Only one file on disk.

So basically we need to:

  • Copy if we need a duplicate of the file which is independent of the other file.
  • Do a hard link if we need a file that is a linked very hard to the original file (all contents of the file will be edited whenever we edit one file and the link will stay even if we move the original file to a separate location) and wanted to avoid different versions (of the file) and space eating duplicates.
  • Do a soft (symbolic) link if we wanted a shortcut to the file.

And that’s it! the main differences between Copy, Hard and Soft Link. Hope we all learned something new in this post!

References:

Advertisements

4 thoughts on “Copy vs Hard Link vs Soft (Symbolic) Link

  1. Dear Blogger

    Your piece is the closest I’ve found to a clear, reasonably intuitive explanation of this matter. Thanks! (At least one other site offered what it called a simple explanation, only for me to discover that this was a meaning of ‘simple’ that I had not encountered before).

    One question, though. Could you tell me which type of link the file manager (to be specific, Nemo) in Linux Mint creates (when one selects ‘make link’)? I find links very useful, but I worry about my backup program getting stuck in a loop, if you see what I mean.

    Like

      • Thanks. So, if I backup a directory using a backup tool (the one I use is called ‘Back in Time’), and that directory contains a link made by the file manager, then the backup will *not* include the file or directory (as it may be) to which the link points? (Back in Time does have an option that seems germane to this, but I don’t really understand that option. I suppose I am just asking what behaviour you would expect when copying a folder containing a soft link.) Thanks for your time.

        Like

      • I guess it will not include the contents of the directory where the soft link is pointing. However, I would recommend to test it first in order to verify. I would gladly test the application behavior on soft links if I can find the time.

        Like

Care to comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s