Interesting. I wrote my own that does pretty much the same thing, but in a different way (I only use one hash, so I suspect it will use less memory (but see response below for the final word)).

#! /usr/bin/perl -w use strict; use File::Find; use Digest::MD5; my %digest; my $total_bytes = 0; my $dups = 0; sub wanted { return unless -f $_; my $bytes = -s _; return unless $bytes; if( !open IN, $_ ) { print "Cannot open $_ for input: $!\n"; return; } my $md5 = Digest::MD5->new; my $d = $md5->addfile( *IN )->digest; close IN; if( defined $digest{$d} ) { print "$bytes\t$digest{$d}\t$File::Find::name\n"; $total_bytes += $bytes; ++$dups; } else { $digest{$d} = $File::Find::name; } } foreach my $d ( @ARGV ) { print "=== directory $d\n"; find \&wanted, $d; } printf "Statistics: Duplicates: %12d Bytes: %12d KBytes: %12d MBytes: %12d GBytes: %12d\n", $dups, $total_bytes, $total_bytes / (1024**1), $total_bytes / (1024**2), $total_bytes / (1024**3);

It is very verbose, but that's because I pipe the output into something that can be handed off to users in a spreadsheet so that they can do their own housekeeping (2Gb of duplicates in 45Go of files...).

BTW, you can also save a squidgin of memory by using the digest() method, rather than the hexdigest() method, since the value is not intended for human consumption.


In reply to Re: Find duplicate files. by grinder
in thread Find duplicate files. by salvadors

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.