opscape

Text processing

md5sum

Compute or verify MD5 checksums; fine for spotting accidental changes, not for security.

md5sum [OPTION...] [FILE...]

8 of 8 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: md5sum(1)

md5sum prints the MD5 hash of each file: 32 hex digits, two spaces and the name. It works exactly like sha256sum, including -c to verify a saved list, and reads standard input when no file is given.

MD5 is cryptographically broken: it is easy to construct two different files with the same MD5 hash. It is still fine for catching accidental corruption and for finding duplicate files, and you will meet it in older download pages, package metadata and cloud storage ETags. For anything where someone might tamper with the data on purpose, use sha256sum.

Examples

Hash a file

md5sum todo.txt
explain
output
70472651797642aa9a78f7cbfb9416c5  todo.txt

The 32-digit hex digest, two spaces, then the file name.

Hash several files

md5sum photos/*.png
explain
output
c2e73eb75388960ec708ffdec1b07100  photos/IMG_2041.png
94c52963b91dc4d437b2dabc0e2f2253  photos/beach.png
f76762589d1a641cba99b6ddf9966df6  photos/forest.png

One line per file, ready to be saved as a checklist.

Save and verify checksums

md5sum logs/*.log > logs.md5
md5sum -c logs.md5
output
logs/app.log: OK
logs/error.log: OK

-c recomputes each hash from the list and prints OK for each file that still matches.

A file that changed

md5sum todo.txt > todo.md5
echo 'call the bank' >> todo.txt
md5sum -c todo.md5
outputexit 1
todo.txt: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

Any change to the file changes its hash, so the check reports FAILED and the command exits with 1.

Find duplicate files

Setup run before this example
cp photos/beach.png photos/beach-copy.png
cp notes.txt notes-backup.txt
md5sum *.txt photos/*.png | sort | uniq -w 32 -D
explain
output
94c52963b91dc4d437b2dabc0e2f2253  photos/beach-copy.png
94c52963b91dc4d437b2dabc0e2f2253  photos/beach.png
c4bdac40a6d8b7dee028ccb8dc4f04fa  notes-backup.txt
c4bdac40a6d8b7dee028ccb8dc4f04fa  notes.txt

Files with identical content have identical hashes. Sorting brings them together and uniq -w 32 -D prints every line whose first 32 characters (the hash) repeat: the two copies of the notes and the two beach pictures.

Hash a string

printf 'hello' | md5sum
explain
output
5d41402abc4b2a76b9719d911017c592  -

With no file, md5sum hashes standard input and prints - as the name. Use printf, not echo, so no newline is hashed.

Check that a copy is identical

cp access.log /tmp/access.log
md5sum access.log /tmp/access.log
output
2807586b63933d6cf3c3320341980306  access.log
2807586b63933d6cf3c3320341980306  /tmp/access.log

The same hash for both files confirms the copy is intact. For a plain yes/no on two local files, cmp is faster and exact.

A listed file that no longer exists

md5sum notes.txt > notes.md5
mv notes.txt meeting-notes.txt
md5sum -c notes.md5
outputexit 1
md5sum: notes.txt: No such file or directory
notes.txt: FAILED open or read
md5sum: WARNING: 1 listed file could not be read

Checksum lists store names, not content locations. After the rename, md5sum -c cannot open notes.txt, reports FAILED open or read and exits with 1.

Common pitfalls

  • MD5 collisions can be produced deliberately. Don't use MD5 to verify downloads from untrusted sources, sign data or store passwords.

  • echo text | md5sum includes the newline. Use printf '%s' text | md5sum.

  • File names in a checksum list are relative to the directory where it was made. Run md5sum -c from that same directory.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • macOS uses md5 instead, which prints MD5 (file) = hash; md5 -r prints the GNU-style hash-then-name order. md5sum --tag produces the BSD style on Linux.

Options worth knowing

A selection, described in our own words. For the full list, see md5sum(1) or md5sum --help.

OptionWhat it does
-c, --checkVerify files against the checksums listed in FILE.
--quietWith -c, don't print OK lines.
--statusWith -c, print nothing; use the exit status.
--ignore-missingWith -c, skip files that do not exist.
--strictWith -c, fail on improperly formatted lines.
--tagPrint BSD-style lines: MD5 (file) = hash.
-b, --binaryBinary mode; no difference on Linux.
-z, --zeroEnd output lines with NUL instead of newline.

Related