Hello
I want to find all the hard links that are related to particular inode number.
For example, I have this directory structure
./test ./test/dir1 ./test/dir2 ./test/dir3
Code:
# ls -ld test/
drwxr-xr-x. 5 root root 42 Feb 9 21:42 test
# ls -l test/
drwxr-xr-x. 2 root root 6 Feb 9 20:37 dir1
drwxr-xr-x. 2 root root 6 Feb 9 20:37 dir2
drwxr-xr-x. 2 root root 6 Feb 9 21:42 dir3
From some papers on Linux that i received, the author of that papers tells how to find the number of immediate sub directories in a directory easy way. He explains to look for number of hard links in a directory listing and subtract it from 2, which will give the number of immediate subdirectories in it.
On why subtract by 2, he explains the inode for the directory itself and the
. file in that directory which represent current directory, refer to same inode. So less 2.
So in my example, the count is 5, that gives me 3 sub directories, which is correct.
Code:
# ls -ldi test test/.
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/.
And since each subdirectory has
.. file in them that link to parent directory, ie.,
test directory in this case, which counts for that remaining 3.
Code:
# ls -ldi test/dir1/.. test/dir2/.. test/dir3/..
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/dir1/..
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/dir2/..
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/dir3/..
Cool. So far so good. Now that i know there is inode 67395691, i want to see al the hard links attached to it.
I tried
Code:
# find ./ -inum 67395691
./test
but it only points to
./test dir. I want to see all the links that are pointing to that inode, like
Code:
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/.
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/dir1/..
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/dir2/..
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test/dir3/..
How do I achieve that?
Sorry for long illustration.
Thanks in advance.