From FreeBSDwiki
Jump to: navigation, search

For the full description of the 'ln' command please view this article.

In Unixlike OS'es, there are two type of links: hard links and "soft" (or symbolic) links.

Soft links, aka symbolic links or "symlinks", are roughly analogous to MS Windows' "shortcuts" - they are complete files in their own right which serve as pointers. For example, a symlink might serve to say to the filesystem, "if you're looking for /usr/bin/myprogram, go to /usr/sbin/myprogram".

Hard links make a copy of the metadata for the file that is linked - there is still only one set of the actual data for the file, but there are now directory entries in two places which reference it.

Some differences between hard and soft links:

  • You can symlink a directory, but you cannot create a hard link to a directory - hard links are only applicable to actual files.
  • If you symlink a file and delete the original, the symlink is worthless. However, if you hardlink a file and delete the original, the file itself still exists as the hardlink. The actual file data will not be deleted until all hard pointers to it are removed, so if you hardlink the same file nine times, the file itself won't really be gone until all ten pointers to it are gone. If a single one of those pointers survives, no matter which one it is, the file will still be there.
  • You can symlink across physical device boundaries (ie a symlink from /var to /usr when they are on separate partitions or separate physical devices entirely). You CANNOT hardlink across device boundaries - hardlinks can only be used within the same partition of the same device.

Both hard and soft links are created using the ln command.

Personal tools