Name

md5 — stdin  stdout  - file  -- opt  --help  --version

Synopsis

md5 files

The md5 command does not compare files, but it does something related: it computes and displays checksums of files to verify that the files are unchanged. It produces 32-byte checksums using the MD5 algorithm:

md5 myfile
MD5 (myfile) = d3b07384d113edec49eaa6238ad5ff00

If one file differs even slightly from another file, the two files are highly unlikely to have the same MD5 checksum, so comparing checksums is a reasonably reliable way to detect if two files differ. Here we write two checksums to two files (piping through cut to extract the checksum value after the equals sign) and compare them:

md5 myfile1 | cut -d= -f2 > sum1md5 myfile2 | cut -d= -f2 > sum2diff -q sum1 sum2
Files sum1 and sum2 differ
➜ rm sum1 sum2                     Clean up

When a very large file is available for download on the Internet, such as a disk image, its creator often publishes the checksum. When you download such a file, you can compute the checksum locally and compare it easily to the published one, verifying that the large file was not corrupted during transmission:

md5 diskfile.iso > mine.md5diff -q original.md5 mine.md5

Some other programs similar to md5 are sum and cksum, which use different algorithms to compute their checksums. sum is compatible with Unix systems, specifically BSD Unix (the default) or System V Unix (-s option), and cksum produces a CRC checksum:

sum myfile
12410  3  myfile
➜ cksum myfile 1204834076 2863 myfile ...

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.