Well, this is kind of a long line, and it assumes that you have the gnu or bsd "find", "xargs" and "md5" available on your system as standard utilities (in addition to perl). It could be shorter, but for a few extra characters in the script to use file size together with MD5, you get a lot of extra safety (it's possible to get the same MD5 signature from two files with different contents, but this is far less likely when the files are the same size).
# output of "md5" is one line per file: "MD5 (filename) = signature"
find . -type f -print0 | xargs -0 md5 |
perl -ne '/MD5 \((.*)\) = (\S+)/ or next; ($f,$m)=($1,$2); $s=-s $f;
+if($h{"$m $s"}){unlink $f} $h{"$m $s"}++'
As suggested by others, you can use the Digest::MD5 module in the perl script (and make the script a bit longer), in case you want to save run time by only computing MD5 signatures on sets of files that are the same size.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.