Name
md5sum files | --check file — coreutils
Synopsis
/usr/bin stdin stdout - file -- opt --help --versionThe md5sum command prints a 32-byte checksum of the given files, using the MD5 algorithm (see http://www.faqs.org/rfcs/rfc1321.html for the technical details):
$ md5sum myfile dd63602df1cceb57966d085524c3980f myfile
Two different files are highly unlikely to have the same MD5 checksum, so comparing checksums is a reasonably reliable way to detect if two files differ:
$ md5sum myfile1 > sum1 $ md5sum myfile2 > sum2 $ diff -q sum1 sum2 Files sum1 and sum2 differ
or if a set of files has changed, using --check:
$ md5sum file1 file2 file3 > mysum $ md5sum --check mysum file1: OK file2: OK file3: OK $ echo "new data" > file2 $ md5sum --check mysum file1: OK file2: FAILED file3: OK md5sum: WARNING: 1 of 3 computed checksums did NOT match
Two other programs similar to md5sum are sum and cksum, which use different algorithms to compute their checksums. sum is compatible with other Unix systems, specifically BSD Unix (the default) or System V Unix (-s option), and cksum produces a CRC checksum:
$ sum myfile 12410 3 $ sum -s myfile 47909 6 myfile $ cksum myfile 1204834076 2863 myfile
The first integer is a checksum and the second is a block count. But as you can see, these checksums are small numbers and therefore unreliable, since files could have identical checksums by coincidence. md5sum is by far the best.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access