#!/usr/bin/perl -wT use Digest::MD5; use File::Find; use IO::File; use strict; $| = 1; $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; my $ctx = Digest::MD5->new; my %digest; my $path = $ARGV[0] || '.'; find ({ 'wanted' => sub { if (-f $_) { lstat; if ((-r _) && (!-l _)) { $ctx->reset; my $fh = IO::File->new($_, 'r'); $ctx->addfile(\$fh); my $md5 = $ctx->hexdigest; if (exists $digest{$md5}) { push @{$digest{$md5}->{'dupes'}}, $_; } else { $digest{$md5} = { 'file' => $_, 'dupes' => [] } } } } else { print "Searching $_\n"; } }, 'no_chdir' => 1 }, $path); print "There are ", ((scalar @{$digest{$_}->{'dupes'}}) || 0), " duplicate files.\n"; exit 0;