How to get all the hard links that link to the same file quickly?
Tom H
tomh0665 at gmail.com
Sat Apr 23 14:44:01 UTC 2011
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.
More information about the ubuntu-users
mailing list