List all hard links related to inode...
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/ 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/. Code:
# ls -ldi test/dir1/.. test/dir2/.. test/dir3/.. I tried Code:
# find ./ -inum 67395691 Code:
67395691 drwxr-xr-x. 5 root root 42 Feb 9 21:42 test Sorry for long illustration. Thanks in advance. |
Easy question. hardlinks cannot be directories. So the one file is the only one used by that inode.
|
You can go by the name of the directory to find, by name, the subdirectories and use stat to print the inode:
Code:
find ./test/ -type d -exec stat --printf="%i\t%n\n" {} \; |
for directories there are no hardlinks, the only exception is what you listed.
So: dir dir/. dir/subdir1/.. dir/subdir2/.. dir/subdir3/.. dir/subdir4/.. dir/subdir5/.. dir/subdir6/.. ... you only need to list the subdirs find by default does not list . and .. actually see man find, and look for -noleaf |
Sorry for delayed response. So basically hard link cannot be created on directory. I didn't knew that. Then searching for what other directories are connected to that inode doesn't make sense.
Thanks. |
In several parts of the system there is the tacit assumption that a filesystem directory structure is a tree. Making arbitrary hard links to a directory breaks that. In the distant past in Unix, it was possible for the root user to make hard links to a directory**. Anyone who tried that (raises hand, sheepishly) ended up with a broken filesystem and had to resort to the low-level filesystem debugger to repair it.
** The rename command had to do that to rename directories, since there was no rename(2) system call at the time. |
just two additional comments:
1. hard links on directories are possible, not only theoretically, but "in real filesystems" too, just it is disabled. 2. using other kind of filesystem(s) I found hard links among dirs and that caused really strange errors. So better to not use them.... |
All times are GMT -5. The time now is 02:36 PM. |