When we create a directory mkdir foo
, initially the number of hard links is 2 ls -ld foo
-because of the directory itself and the shortcut dot .
inside that directory. If we create a new directory inside that foo, the number of hard links for foo increases -because of the parent directory's shortcut ..
inside new directory. So the number of hard links for foo should be 1+1+number of directories inside foo. In Ubuntu there is no problem, but in Mac OS X, for some directories (let's say ~/Documents
) this formula for total number of hard links does not work. Usually the number of hard links is bigger than 1+1+number of directories inside Documents
. When I try to find files by using that directory's idone by using find / -inum inumofDocuments -print
it only returns Documents. So I wonder where are the other files with that inode number are located?
Asked
Active
Viewed 211 times
0

user3140972
- 995
- 6
- 11
-
Just a guess - have you tried looking in `NSURL`? `NSURL` can keep track of a file/directory it doesn't matter if you move it to any other place or rename it. may be its keeping hard links to the actual file/directory. BTW in `Finder` the favorites are `NSURL`s. – bikram990 Jun 11 '14 at 06:24
-
one more point - if you delete some items from `Documents` it will move them the trash and those folders will still have a hardlink to `Documents` folder – bikram990 Jun 11 '14 at 06:31
-
finding the path based on Inode isn't easy... but worrying about the link count is like worrying About refcount – Grady Player Jun 11 '14 at 07:40
-
For some reason in OSX, a file increments the hardlink counter: mkdir testdir; cd testdir; ls -la; touch blah; ls -la. You will see that adding the file blah makes the number of hardlinks to '.' go from 2 -> 3. This is osx specific because this is not the case in Ubuntu/RHEL. – jshort Jul 16 '14 at 17:31
-
Thanks @jshort I had not paid attention to that. Obviously I did not expect regular files to increase number of hard links, but in OS X they do... – user3140972 Jul 18 '14 at 17:02