D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Find hard links

 

Simon Williams wrote:

> I've got some files which I have been hard linking to save time and 
> space. Now I'm trying to reorganise those files, but I don't know what 
> links to what.
> 
> Is there some command which will list all the files pointing to the same 
> data?

Not that I know of, so I wrote this little script of pleasure.

Steve


#! /usr/bin/perl 

use File::Find;

my $dir = $ARGV[0] || '.';

my $nodes;

sub wanted {

  my ($inode,$nlink) = (lstat($_))[1,3];

  return unless -f && $nlink > 1;

  push(@{$$nodes{$inode}}, $File::Find::name); 
}

File::Find::find({wanted => \&wanted}, $dir);

print map { "@$_\n" } values %$nodes;

  

    


-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html