Skip to Content
Linux Pocket Guide, 2nd Edition
book

Linux Pocket Guide, 2nd Edition

by Daniel J. Barrett
March 2012
Beginner to intermediate
230 pages
7h 27m
English
O'Reilly Media, Inc.
Content preview from Linux Pocket Guide, 2nd Edition

Name

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

Synopsis

md5sum files | --check file

The md5sum command works with checksums to verify that files are unchanged. The first form produces the 32-byte checksum of the given files, using the MD5 algorithm:

$ md5sum myfile
dd63602df1cceb57966d085524c3980f  myfile

while the second form tests whether a checksum matches its file, using --check:

$ md5sum file1 file2 file3 > mysum
$ cat mysum
90a022707ca5b5fc8f465e7cbb954987  file1
86d19ef79d33c28cf0c9ba882f25cdb8  file2
d0dc53c9941e33a10e7f38ecc0de772f  file3
$ 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 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 | cut -c1-32 > sum1
$ md5sum myfile2 | cut -c1-32 > sum2
$ diff -q sum1 sum2
Files sum1 and sum2 differ

Some 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 ...

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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Linux Pocket Guide, 3rd Edition

Linux Pocket Guide, 3rd Edition

Daniel J. Barrett
Linux Pocket Guide

Linux Pocket Guide

Daniel J. Barrett

Publisher Resources

ISBN: 9781449332969Errata Page