/ Published in: Perl
URL: http://www.perl.com/pub/a/2004/08/09/commandline.html?page=2
This one-liner helps to determine if two or more files have the same
checksum. It works by piping the output from cksum to Perl, which
takes note of the first checksum and compares each subsequent file's
checksum to that value.
Assume an example session where we have three identical files and two that are different
>echo bart > bart
>cp bart bart1
>cp bart bart2
>echo milhouse > mvh
>echo lisa > lisa
two files with the same checksum, produce no output
>cksum bart bart1 | perl -ane '$x ||= $F[0]; warn if $x != $F[0];'
if a there is a different checksum, the line numbers printed are the indexes of those files
>cksum bart bart1 mvh bart2 lisa | perl -ane '$x ||= $F[0]; warn if $x != $F[0];'
Warning: something's wrong at -e line 1, <> line 3.
Warning: something's wrong at -e line 1, <> line 5.
Expand |
Embed | Plain Text
cksum file1 file2 | perl -ane '$x ||= $F[0]; warn if $x != $F[0]' # This can be shortened slightly, to: cksum file1 file2 | perl -ane 'warn if $F[0] != ($x ||= $F[0])' # If the checksum value we need to match is already known, that can be # shortened to: cksum file1 file2 | perl -ane 'warn if "664253628" != $F[0]' # on Mac, if you have copied a checksum value into the clipboard, use # pbpaste to do the comparison cksum file1 file2 | perl -ane 'warn if `pbpaste` != $F[0]'
You need to login to post a comment.
