Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I hear that you can now create soft links in Vista too. So, what is the difference between a soft (symbolic) link and a hard link on UNIX/Linux/Vista?

Are there advantages of using one over the other? Or do they just serve two distinct purposes?

share|improve this question
    
In practical terms, the answer is that you almost always want to use a symbolic link. My understanding is that hard links are mostly for preserving space, especially in things like snapshots and incremental backups, where successive snapshots have many identical files that are unlikely to change in the future. –  Ryan Thompson Sep 8 '09 at 22:58
    
Should this be migrated to Unix & Linux? See unix.stackexchange.com/questions/9575/… –  ripper234 Mar 19 '11 at 9:05
1  
No it should not be migrated. As the original question is not specific to Unix only -- Windows supports hard and soft links. –  Richard West May 23 '11 at 2:23
    
some applications will break (and sometimes badly) if you use a soft link - expecially for directories: the softlink will get dereferenced, and when it is and the application compares, say /var/opt/log/appname (its config) with the dereferenced value, say /apps/appname/logs, it will complain this it's not a match. The fix for this is to use a mount --bind (on Linux) to remount the original directory to the new location. –  warren Aug 18 '11 at 16:34
    
+1; Exactly what I use hard links for on my home Linux system - blog.interlinked.org/tutorials/rsync_time_machine.html –  Bryan Dec 11 '11 at 19:49
show 2 more comments

3 Answers

up vote 57 down vote accepted

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.)

share|improve this answer
    
Nice summary. Every Linux user should know this (though hard links are very uncommon). –  Artem Russakovskii May 21 '09 at 2:01
    
dmckee's answer has the details about the semantics pretty much exact. The only detail I would add is an explanation of what happens at a higher level: a soft link is a file on its own, while a hard link is a directory entry pointing to existing data. Wikipedia has more details about hard and soft links. –  Mr. Shiny and New 安宇 May 21 '09 at 13:19
    
nice sum up, very usefull –  Razique Sep 8 '09 at 23:07
7  
It should also be noted that hard links share permissions as well as ownership information. –  Corey S. Dec 16 '09 at 22:36
4  
Please add that 2 hardlinks are automatically created with the name . and .. each time you create a folder. In Linux that those are the only valid hardlinks to a folder. –  Mircea Vutcovici Apr 18 '11 at 18:31
add comment

The summary is that a symbolic / short link acts as a shortcut to the first file's location, whereas a hardlink is a shortcut to the file on the disk.

If you delete the target of a soft link then the soft link will cease to work, but if you delete one copy of a hard link, the file will remain on the disk until all hard links to it are removed. In effect all filenames are hardlinks to the file on the disk.

There are also certain restrictions, eg I don't think you can create hard links of folders, but you can create soft links of them. Soft links can also point to files/folders on different drives and partitions whereas hard links can't.

share|improve this answer
add comment

The MS Windows system always uses soft links (shortcuts). That is, the link simply acts as a shortcut pointing to the file location. If the location of the original is moved, the link breaks. Furthermore, what you do to the shortcut (such as changing permissions, or changing the name of the shortcut) does not affect the actual file.

So the question started with an incorrect assumption. Yes, Vista uses softlinks, but it is not new, that is waht an MS shortcut is.

share|improve this answer
2  
No, NTFS supports hardlinks and has since NTFS 3.1 (the current version since XP/2003). –  Chris S Sep 27 '12 at 16:33
add comment

protected by Chris S Sep 27 '12 at 16:36

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.