Skip to content

Instantly share code, notes, and snippets.

@peplin
Created June 16, 2014 13:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save peplin/4f2570e046b5bc144352 to your computer and use it in GitHub Desktop.
Save peplin/4f2570e046b5bc144352 to your computer and use it in GitHub Desktop.
Perl script to find duplicate filenames
#!/usr/bin/perl -w
use File::Find;
my %files;
my @dirs;
foreach $argnum (0 .. $#ARGV) {
push(@dirs, $ARGV[$argnum]);
}
find(\&check_file, @dirs);
local $" = ", ";
foreach my $size (sort {$b <=> $a} keys %files) {
next unless @{$files{$size}} > 1;
my %names;
foreach my $path (@{$files{$size}}) {
$path =~ /([^\/]*$)/;
push @{$names{$1}}, $path;
}
foreach my $filename (keys %names) {
next unless @{$names{$filename}} > 1;
@{$names{$filename}}[0] =~ s/ /\\ /g;
@{$names{$filename}}[0] =~ s/'/\\'/g;
print @{$names{$filename}}, "\n";
#print @{$names{$filename}}[0], "\n";
#print @{$names{$filename}}[0], "\n";
}
}
sub check_file {
-f && push @{$files{(stat(_))[7]}}, $File::Find::name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment