Created
July 6, 2012 06:47
-
-
Save briandfoy/3058473 to your computer and use it in GitHub Desktop.
Dup killer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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