#!/usr/bin/perl use strict; use warnings; my ( $path, $file ) = @ARGV; die "Usage: $0 search/path data.file\n" unless ( -d $path and -f $file ); my ( $inode, $nlinks ) = ( stat _ )[1,3]; die "$file has no hard links\n" if $nlinks == 1; my ( $chld, $nfound, @found ); $SIG{HUP} = sub { $nfound++; `kill $chld` if $nfound == $nlinks }; $chld = open( FIND, "-|", "find $path -inum $inode -print0 -exec kill -HUP $$ \\;" ) or die "find: $!\n"; $/ = chr(0); while ( ) { chomp; push @found, $_; } printf( "found %d of %d links for %s in %s\n", scalar @found, $nlinks, $inode, $path ); print join( "\n", @found ), "\n";