5

I've used hard links in the past, but they seem to make a bit of a mess of things...

When is the proper time to use Hard links? What are the best practices for when and where to use hard linking?

Thanks,

Dan

7 Answers 7

8

Hard-links can be very useful when you want to have the same contents (and same permissions!) in several files on the same filesystem.

Take for example a package manager, that creates a /usr/share/doc/$packagename directory for each package that is installed and inside that directory a file called LICENSE with the license information of the package. Many packages on a typical Linux system are GPL licensed, so instead of having 200 copies of the GPL on the filesystem there could be only one copy and 199 links.

Distributed version control systems copy the whole repository on clone, there is no checkout like in svn. If several clones of the same repository are on the same filesystem they can share part of the (immutable) files by using hard links (git does this, and darcs too IIRC).

Many backup solutions also use hardlinks, like rsnapshot and backuppc.

2
  • Backup systems is probably one of the most common usages. Arguably it is a primitive version of deduplication.
    – Zoredache
    Mar 14, 2010 at 20:39
  • 1
    Just a quick note that hard link cannot traverse file system mounts, for that you need to symbolic links. Mar 20, 2010 at 14:47
5

The best use I've seen of hardlinks is with rsnapshot.

2
  • And backuppc. That's a pretty efficient use of hardlinks. Mar 14, 2010 at 20:00
  • Also faubackup.
    – Teddy
    Apr 8, 2010 at 20:46
1

If you want to achieve, that the file is removed only, when all hard links are removed.

2
  • uh, I understand that is what it does... just doesn't seem that useful to me? I have never found a great time to use it, and was wondering if other people have.
    – Dan
    Mar 14, 2010 at 17:37
  • 1
    I don't see all that many real life applications either :-) Mar 14, 2010 at 17:48
1

Setting up honeypots with circular links in the file system hierarchy, so an intruder's "find" runs forever.

4
  • 1
    How would you do this with hard links? On recent *nix you cannot create hard links to directories.
    – Zoredache
    Mar 14, 2010 at 20:37
  • @zoredache: Works for privileged users. Check the docs for link(2).
    – mpez0
    Mar 15, 2010 at 13:45
  • It also breaks the file system, and I would bet that the next scheduled fsck removes the link.
    – Teddy
    Apr 8, 2010 at 20:47
  • @Teddy: Try it. It certainly didn't used to break the file system. And fsck is fine with it.
    – mpez0
    Apr 9, 2010 at 12:30
0

My users got an folder ~/remote_access with amongst others windows winscp.exe in it. This binary is a hardlink.

So if there comes a new version, I just copy it to my home and all users have the new version ready to copy to their usb stick. It`s like a poor mans automatic software upgrade ;-)

0

I have a web server where users are only allowed FTP-access (i.e. not SSH) and chroot-ed to their home directory for security purposes. I hardlink the specific file containing their Apache VirtualHost definitions into their home directory so that they can read it i.e. they have visibility into the parts of the config that are relevant to them. This way I don't need to give them access to /etc/apache (or other parts of the filesystem).

0

Linux vserver also can use it as a deduplication strategy. You can generally use a hardlink across the boundaries of a chroot, unlike a symlink - but do not forget that whatever manages to change the content of the file also does so outside the chroot, and in the worst case into another chroot. IIRC vserver uses a COW mechanism on top of it...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .