#!/usr/bin/perl # 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 $mdprog = "md5"; # Set to command name of "md5" program, or # null string if you don't have it. $sep = "\000"; foreach $dir (@ARGV) { open (FIND, "find $dir -type f -print |") || die ("open failed: $!"); while () { chop; ($leaf = $_) =~ s-.*/--; $map{$leaf} .= "$_$sep"; } close FIND; } $md = ""; foreach $leaf (sort keys %map) { $files = $map{$leaf}; chop $files; @paths = split($sep, $files); if ($#paths > 0) { for ($i=0; $i<=$#paths; $i++) { $path = $paths[$i]; $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"); } }