[OT] Hardlinks and directories

Marko Vojinovic vvmarko at gmail.com
Fri Feb 12 14:06:23 UTC 2010


On Friday 12 February 2010 07:23:02 Suvayu Ali wrote:
> $ ln muse test
> ln: `muse': hard link not allowed for directory
> 
> So I did a little searching and found its not exactly a forbidden. So
> far the closest to an understandable explanation/reasoning I came across
> was a discussion in lwn[1]. So my question is how are hardlinks so
> different from softlinks?

If you are familiar with the concept of memory pointers in some (any) 
programming language, this is basically the same thing.

A hard link is a pointer to some data on the disk.

A soft link is a pointer to a pointer.

Now, hard links are not allowed for directories since they would allow for 
creation of loops (a directory containing itself), which is a Bad Idea, since 
it breaks recursion. The filesystem needs to be a *tree* if recursion is to 
function, so loops are forbidden (how would you delete a directory which 
contains itself?).

However, soft links to directories are allowed, since they are just pointers 
to other pointers, which makes them distinguishable from regular pointers 
(hard links), and thus recursion algorithms can work around them ("don't 
follow a symbolic link when recursing" is a typical option you can find in a 
man page of various tools).

HTH, :-)
Marko






More information about the users mailing list