The only way I know is:
find /home -xdev -samefile file1
But it's really slow. I would like to find a tool like locate
.
The real problems comes when you have a lot of file, I suppose the operation is O(n).
Two different directories may contain identical name-inode mappings; using either pathname will lead to the same inode number and thus to the same file. Thus, on Unix, a file can have many names, even across different directories. You may use any of the several names of a file to find the inode for the file.
To get the number of inodes of files in a directory, for example, the root directory, open a terminal window and run the following ls command, where the -l option means long listing format, -a means all files and -i mean to print the index number of each file.
A file has one single inode since it is the inode that uniquely identifies the file. You can have several names/paths pointing to the same inode, this is called "hard links".
There is no mapping from inode
to name. The only way is to walk the entire filesystem, which as you pointed out is O(number of files). (Actually, I think it's θ(number of files)).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With