hard links

David A. Bandel david.bandel at gmail.com
Sat Oct 27 21:00:30 PDT 2007


On 10/27/07, Collins Richey <crichey at gmail.com> wrote:
> Thought for the weekend.
>
> What is the purpose of a hard link, and does anything in Linux land
> use hard links?

I'll answer your question in reverse order:
lots of stuff uses it.  look through /bin and /sbin using:
ls -ali | sort
here's my output:
david at tole:/bin$ ls -ali | sort | uniq -D -w 7
2572294 -rwxr-xr-x  3 root root   25140 May 21 00:44 bunzip2
2572294 -rwxr-xr-x  3 root root   25140 May 21 00:44 bzcat
2572294 -rwxr-xr-x  3 root root   25140 May 21 00:44 bzip2
2572296 -rwxr-xr-x  2 root root    2105 May 21 00:43 bzcmp
2572296 -rwxr-xr-x  2 root root    2105 May 21 00:43 bzdiff
2572297 -rwxr-xr-x  3 root root    3642 May 21 00:43 bzegrep
2572297 -rwxr-xr-x  3 root root    3642 May 21 00:43 bzfgrep
2572297 -rwxr-xr-x  3 root root    3642 May 21 00:43 bzgrep
2572300 -rwxr-xr-x  2 root root    1297 May 21 00:43 bzless
2572300 -rwxr-xr-x  2 root root    1297 May 21 00:43 bzmore
2588739 -rwxr-xr-x  2 root root      61 Aug 18 21:49 gunzip
2588739 -rwxr-xr-x  2 root root      61 Aug 18 21:49 uncompress

So for example, when you call bunzip2 or bzip2, you're calling the
same binary, just with a different name.   This is like calling the
binary with different options, but easier to remember.

Take a look at `man bzip2` to see what I mean.

ifup/ifdown on my system is the same as are many of the fsck binaries.

Can you do this with symlinks?  Yes.  However, if you symlink b to a,
then erase a, b becomes a dangling link.  If you hard link b to a,
then erase a, the file still exists as b.  See `man ln`.

Ciao,

David A. Bandel
-- 
Focus on the dream, not the competition.
            - Nemesis Air Racing Team motto



More information about the Linux-users mailing list