How to find all the links to a directory

When I stat a directory I get a listing that tell me there are 5 links to the directory.

stat dir

My question is how do I get information (names and locations) to all these 5 links?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You just need ls (or find).

When you create a directory, its link count starts at 2:

  • One for the directory itself
  • One for the . link inside itself

The other thing that increases the directory’s link count is its subdirectories: they all have a .. entry linking back to their parent, adding one to its link count.

You can’t hardlink directories in Linux, so these are the only things that count towards the link count – two plus number of subdirectories.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x