LinuxQuestions.org
Visit Jeremy's Blog.
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, 01: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, 01:27 PM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
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, 01: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, 01:54 PM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

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

Rep: Reputation: 71
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, 09:15 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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, 09: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:15 AM
ls long listing format - number of hard links / directories sljunkie Linux - Newbie 3 09-15-2011 05:43 PM
Hard links Number and Directories ahmedb72 Solaris / OpenSolaris 2 07-04-2007 02:54 PM
technical question about hard links v soft links 7stud Linux - Newbie 2 02-23-2007 07:57 PM
Why we can't create hard links for directories in linux? tdhanu_2000 Linux - Kernel 11 06-11-2006 05:14 AM


All times are GMT -5. The time now is 12:36 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration