4

I have read lots of posts on What is the difference between soft and hard link but still am a bit vague on the difference. I wonder could somebody give just one or two example(s) of when you would want to use a Hard link instead of a soft? Just a real world example to help people understand.

The answers in the above link may be thorough, but they may be too complex they are for me to really grasp WHY I would want to use one or the other. Also, they are just a bit complex in general :P.

I think this question could help me and a lot of others understand the answers in the link above.

  • Not a duplicate but I think you'll find terdon's answer useful: Are hard links equivalent to Windows shortcuts? – Sylvain Pineau Aug 26 '15 at 09:21
  • 1
    This should be asked on U&L not AskUbuntu since it is about the Linux filesystem, not about Ubuntu. See http://unix.stackexchange.com/questions/20670/why-do-hard-links-exist – Rinzwind Aug 26 '15 at 10:07
  • Just made a post about the Breakdown between Hard Links vs Soft Links vs Bind @ U&L, [http://unix.stackexchange.com/questions/9575/what-is-the-difference-between-symbolic-and-hard-links/226223#226223](Hard Link vs Soft Link vs BIND) , Thanks @Rinzwind, that link lead me to Another link (see bellow comment) that helped me FINALLY understand! I used a picture in my explanation that I think might help others. – FreeSoftwareServers Aug 29 '15 at 05:34

1 Answers1

3

In short: don't bother using the hard links.

Hardlink are rarely used (maybe due to legacy unix bugs, who knows), so let see the advantages of hard links, and what scenario could require that feature.

  1. less space consumption (just the inode entry): could be useful if your requirements impose usage of gazillions of links
  2. file reference counting: Within the same filesystem, you can create multiple directory structures containing hard-linked files. It enables you to:

    • have multiple thematic directory structures (Docs/House/Taxes/fx2015.pdf vs Docs/Taxes/2015/fx.pdf)
    • even create backup snapshots as seen here
    • reorganize, rename and delete your documents without naming troubles

Ohh.. you think it's nice ? perfect directory structures for me ? well no.. It will depends on the application used, but when some paranoïd application will save your files, they will do, instead of overwriting it :

  • create a new file and write to that file
  • on success : swap the new and existing file with renaming, delete the old file
  • on failure, data is left unchanged

So, your multiple file names pointing to the same data are now pointing to different data, and you simply cannot tell the difference.

JB.
  • 779
  • This guy has a great reason IMO to use Hard-Links [http://www.mikerubel.org/computers/rsync_snapshots/#Incremental](Rsync Incremental Backups) – FreeSoftwareServers Aug 29 '15 at 04:36
  • @FreeSoftwareServers yeah.. it looked nice 10 years ago. Nowadays you can use ZFS or BTRFS and you have the snapshots for free. But Indeed it's a good reason. – JB. Aug 31 '15 at 08:27
  • Yea i guess, i don' mean to be harrsh but my reason for downvote was that I asked for a reason to USE them, not "in short: don't use them" – FreeSoftwareServers Sep 01 '15 at 18:10