This find
command should print all files under directory ./b
that link to files under directory ./a
.
find ./a -type f -exec find ./b -samefile {} -printf "%p hard link to {}" \;
An example, given file paths and inode numbers
$ find -type f -printf '%p:%i\n' | sort | column -t -s:
./a/f 12977541
./b/f 12977577 # unique file
./c/f 12977541 # points to same file as path ./a/f
#file inode
Run the find command against directory ./a
and ./b
to find any hardlinked files under directory ./c
.
$ find ./a ./b -type f -exec find ./c -samefile {} -printf "%p hard link to {}" \;
./c/f hard link to ./a/f
This is an O(n^2) operation. It will will take a very long time given a large number of files!
Using GNU find 4.4.2, linux 3.13.0-85, Ubuntu 14.04.