-   Linux - Newbie (
-   -   Why are hard links not created in directories? (

anishas 05-17-2015 12:15 PM

Why are hard links not created in directories?
Hi All,

Iam Anisha S.

I would like to know why hard links are not created for directories?


pan64 05-17-2015 12:27 PM

actually they exist, for example the . and .. are both hardlinks. But in general it is not allowed because that may cause strange "side" effects (just imagine - for example - a simple find or ls -r or grep -r may never end).

anishas 05-17-2015 12:43 PM

Hello Pan64,

Thanks for the reply.
Can you please explain me little more clearer.

As per my understanding, Soft links are like shortcuts with different inode number to that of the original file.

But whereas ,in a hardlink the inode numbers are same to the original file and deleting the original file doesnt affect it.Its just they cannot be shared across filesytem.

In that case why can t we create a hardlink for directory ?? It will replicate the original directory correct ?


pan64 05-17-2015 12:54 PM

gengisdave 05-18-2015 06:12 AM

you can't hard link an inode which represent a directory to avoid infinite loop in the directories tree


cd a
mkdir b
cd b
ln ../a c

you'll have an infinite path a/b/c/b/c/b/c/b and so on

this behaviour happens with symlinks, and every (decent) program ignores to follow symlinks in deep searches

jpollard 05-19-2015 08:15 AM

The problem occurs when the filesystem gets repaired.

The directory hierarchy is designed to represent a tree. A directory contains hard links to directories contained within that directory. Each directory has a hard link to its parent.

When you allow for a hard link from elsewhere, you create errors in that tree - it is no longer a tree but a network. Analysing a network is much harder than a simple tree - and can take forever (depending on how the network may loop back on itself) and could make recovery impossible.

anishas 05-19-2015 08:57 AM

Hi jpollard/gengisdave,

Thanks for the info ..It was clear ..

All times are GMT -5. The time now is 04:50 AM.