What are the advantages of symlinks over hard links and viceversa?

10

3

I understand the differences between symbolic and hard links, but I've never understood why choose one or the other.

Javier

Posted 2009-09-08T18:03:11.553

Reputation: 3 053

2

See answers to 'What is the difference between a symbolic link and a hard link?' on StackOverflow: http://stackoverflow.com/questions/185899/what-is-the-difference-between-a-symbolic-link-and-a-hard-link

– pelms – 2009-09-08T18:27:04.003

Answers

10

This has been discussed in some detail on ServerFault.

A hard link traditionally shares the same file system structures (inode in unixspeak), while a soft-link is a pathname redirect.

  • Hardlinks must be on the same filesystem, softlinks can cross filesystems.
  • Hardlinked files stay linked even if you move either of them (unless you move one to another file system triggering the copy-and-delete mechanism). Softlinked files break if you move the target (original), and sometimes when you move the link (Did you use an absolute or relative path? Is it still valid?).
  • Hardlinked files are co-equal, while the original is special in softlinks, and deleting the original deletes the data. The data does not go away until all hardlinks are deleted.
  • Softlinks can point at any target, but most OS/filesystems disallow hardlinking directories to prevent cycles in the filesystem graph (with the exception of the . and .. entries in unix directories which are hard links).
  • Softlinks can require special support from filesystem walking tools. Read up on readlink (2).

(Some details brought back to mind by mat1t. Thanks.)

dmckee --- ex-moderator kitten

Posted 2009-09-08T18:03:11.553

Reputation: 7 311

10

Ronald wrote a hard link can have different permissions in two places. This is not right. Both places share the same inode. Permissions are bound to the inode, not the filename. So hardlinks in two places have exactly the same permissions, access times, ...

hurikhan77

Posted 2009-09-08T18:03:11.553

Reputation: 830

1

symlinks can cross file systems, hard links can't. If you delete the original file, the hardlink still keeps it alive, a symlink doesn't.

bobmcn

Posted 2009-09-08T18:03:11.553

Reputation: 315

0

A hard link essentially means the file lives in two places, it can have different permissions, you can delete it in on place but not the other.

A soft link is just a pointer to the real thing.

A hard link is two (or more) directory entries pointing at the same file. A soft link is a directory entry pointing at another directory entry.

Ronald Pottol

Posted 2009-09-08T18:03:11.553

Reputation: 641