LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-17-2015, 12:15 PM   #1
anishas
LQ Newbie
 
Registered: May 2015
Posts: 4

Rep: Reputation: Disabled
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?

Thanks,
Anisha.
 
Old 05-17-2015, 12:27 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
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).
 
Old 05-17-2015, 12:43 PM   #3
anishas
LQ Newbie
 
Registered: May 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
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 ?

Thanks,
Anisha.
 
Old 05-17-2015, 12:54 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
https://en.wikipedia.org/wiki/Hard_link
 
Old 05-18-2015, 06:12 AM   #5
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

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

Code:
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
 
Old 05-19-2015, 08:15 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
Old 05-19-2015, 08:57 AM   #7
anishas
LQ Newbie
 
Registered: May 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Smile

Hi jpollard/gengisdave,

Thanks for the info ..It was clear ..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard links and soft links - the esoteric details tekra Linux - General 2 10-09-2014 01:15 AM
ls long listing format - number of hard links / directories sljunkie Linux - Newbie 3 09-15-2011 04:43 PM
Hard links Number and Directories ahmedb72 Solaris / OpenSolaris 2 07-04-2007 01:54 PM
technical question about hard links v soft links 7stud Linux - Newbie 2 02-23-2007 06:57 PM
Why we can't create hard links for directories in linux? tdhanu_2000 Linux - Kernel 11 06-11-2006 04:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration