eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' if 0; use strict; # Check filesystem tree (or union of several trees) for unique # leaf names; useful for spotting ambiguities that path-searching # programs could trip over. # For each non-unique leaf name found, it prints out "ls" and "md5" # information for each candidate file. # Martyn Johnson maj@cl.cam.ac.uk # University of Cambridge Computer Lab # Cambridge UK my $mdprog = "md5sum"; # Set to command name of "md5" program, or # null string if you don't have it. my $sep = "\000"; my %map; foreach my $dir (@ARGV) { open (FIND, "find $dir -type f -print |") || die ("open failed: $!"); while () { chop; (my $leaf = $_) =~ s-.*/--; $map{$leaf} .= "$_$sep"; } close FIND; } my $md = ""; foreach my $leaf (sort keys %map) { my $files = $map{$leaf}; chop $files; my @paths = split($sep, $files); if ($#paths > 0) { for (my $i=0; $i<=$#paths; $i++) { my $path = $paths[$i]; my $info = `ls -il "$path"`; chop $info; $info =~ s/\s+/ /g; if ($mdprog) { $md = `$mdprog "$path"`; chop $md; $md =~ s/^.*= / /; } $info =~ s/ ([^ ]+$)/$md $1/; print ("$info\n"); } print ("\n"); } }