Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to find all the file with the same inode?

Tags:

linux

bash

inode

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).

like image 686
Breezeight Avatar asked Aug 27 '09 10:08

Breezeight


People also ask

What does it mean when two files have the same inode?

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.

How do you list inodes?

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.

Can multiple inodes point to the same file path?

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".


1 Answers

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)).

like image 179
Jörg W Mittag Avatar answered Oct 12 '22 00:10

Jörg W Mittag