That sucks!

I have the following script that I use to comb through a filesystem and kill off the duplicates. I'm pretty confident it works correctly. I staked my mp3 collection on it after all. (Weeded out about 3Gb of duplicates in ~55Gb).

#! /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 $_; if( !open IN, $_ ) { print "Cannot open $_ for input: $!\n"; return; } my $md5 = Digest::MD5->new; my $d = $md5->addfile( *IN )->digest; close IN; my $bytes = -s $_; return unless $bytes; if( defined $digest{$d} ) { print "$bytes\t$digest{$d}\t$File::Find::name\n"; unlink $_; $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 ", $dups, $total_bytes, $total_bytes / (1024**1), $total_bytes / (1024**2), $total_bytes / (1024**3); __END__

hope this helps!

--
g r i n d e r

In reply to Re: it's been awhile . . . by grinder
in thread it's been awhile . . . by ashaman

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.