[CLUE-Tech] Finding all hard links to a file

Chris Greene r0x0rman at yahoo.com
Sat May 15 20:46:26 MDT 2004


doh.  The only way I would know how to do it is using a Perl script like 
the one below.

#!/usr/bin/perl

use strict;
use File::Find;

print "Enter filename: ";
chomp(my $file=<STDIN>);
my $inode = (lstat($file))[1];

File::Find::find({wanted => \&wanted}, '.');
exit;

sub wanted {
    my $ino;
    ($ino = (lstat($_))[1]) && ($ino == $inode) && 
print("$File::Find::name\n");
}


Keith Hellman wrote:

>On Sat, May 15, 2004 at 04:31:37PM -0600, Chris Greene wrote:
>  
>
>>You should be able to use find for this.
>>
>>Example: find /home -inum 32092 -print
>>
>>I had a file named 'word' in my home directory.  I created a hard link 
>>with "ln word yo".  When I ran "ls -li" I received:
>>
>>32092 -rw-rw-r--  2 chris chris 2318 May 14 11:16 word
>>32092 -rw-rw-r--  2 chris chris 2318 May 14 11:16 yo
>>
>>You can see they both have the same inode #.  Running "find /home -inum 
>>32092 -print" resulted in:
>>/home/chris/word
>>/home/chris/yo
>>
>>    
>>
>
>Review Angelo's original request, he doesn't want to start with inum, he
>wants a function or script that accepts a *filename* and returns a *list
>of files*.
>
>
>  
>



More information about the clue-tech mailing list