Skip to content

Instantly share code, notes, and snippets.

@xavery
Created July 25, 2015 12:31
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 xavery/e7e52ae22b5d5e2db5ac to your computer and use it in GitHub Desktop.
Save xavery/e7e52ae22b5d5e2db5ac to your computer and use it in GitHub Desktop.
A script that removes duplicate files in its working directory
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
use Digest::file qw(digest_file_hex);
use Cwd;
my %sums;
my @dups;
sub wanted
{
return unless -f $_;
my $sha = digest_file_hex($_, "SHA-256");
if(defined($sums{$sha})) { push @dups, $File::Find::name; }
else { $sums{$sha} = 1; }
}
find(\&wanted, getcwd);
unlink @dups;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment