Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created July 6, 2012 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandfoy/3058473 to your computer and use it in GitHub Desktop.
Save briandfoy/3058473 to your computer and use it in GitHub Desktop.
Dup killer
#!/usr/bin/perl
use warnings;
use strict;
use Cwd;
use Digest::MD5;
my $md5 = Digest::MD5->new();
my %digests = ();
my $dir = cwd;
opendir DIR, $dir or die "Could not open directory: $!\n";
foreach my $file ( readdir( DIR ) )
{
next if $file =~ /^\.\.?$/;
open my($fh), $file or do { warn "$file: $!\n"; next };
$md5->addfile( $fh );
my $digest = $md5->hexdigest;
if( exists $digests{ $digest } )
{
print "$digests{ $digest }\n --> $file\n";
unlink $file
}
else
{
print "$file: $digest\n";
$digests{ $digest } = $file;
}
$md5->reset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment