How to get all the hard links that link to the same file quickly?

Tom H tomh0665 at gmail.com
Sat Apr 23 20:33:16 UTC 2011


On Sat, Apr 23, 2011 at 11:30 AM, Kevin O'Gorman <kogorman at gmail.com> wrote:
> On Sat, Apr 23, 2011 at 7:44 AM, Tom H <tomh0665 at gmail.com> wrote:
>>
>> On Sat, Apr 23, 2011 at 8:40 AM, Peng Yu <pengyu.ut at gmail.com> wrote:
>> >
>> > I'm looking for a fast way to get all the hard links that point to the
>> > same file.
>> >
>> > file="/blah/blah"
>> > find $(stat -c %m "$file") -inum $(stat -c %i "$file")
>> >
>> > Currently, I have a slow way. It traverses the mount point that the
>> > file is on and look for all the files that have the same inum. But
>> > traversing the whole file system is a slow operation. Does the linux
>> > OS keep a table somewhere all the paths pointing to any file or the
>> > linux OS only keep the number of the paths that point to a given inum
>> > but does not keep the actual paths?
>>
>> I've never seen "stat -c %m ..." before. I've just tried it and it
>> doesn't work and isn't in the man pages of either Ubuntu or Fedora.
>> I'd use df to get the mountpoint of a file.
>>
>> I've only ever used "find ... -inum ..." to find hard links but, for
>> an extX filesystem, you can use dumpe2fs to get all the inode tables.
>> That output probably holds the information that you're looking for,
>> but I have no idea whether/how you can query it and get human-readable
>> results from it.
>>
>> --
>> ubuntu-users mailing list
>> ubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
> You can get a pretty good start from
>    find . -exec ls -di {} \; | sort -n
> And (write a script to) look for adjacent entries with the same inode
> number.

By adjacent, do you mean on the same filesystem? (Because, this only
searches below the directory where you are currently.)

You may as well search the mount point in the first step.




More information about the ubuntu-users mailing list