Operations 4 min read

How to Verify File Integrity with md5sum: Commands, Options, and Scripts

This guide explains how to use the Linux md5sum command to generate checksums, compare files, store checksum data, and employ verification options like -c, --quiet, and --status for reliable file integrity checks in scripts and system operations.

Raymond Ops
Raymond Ops
Raymond Ops
How to Verify File Integrity with md5sum: Commands, Options, and Scripts

md5sum command generates an MD5 checksum for a file and can be used to verify whether file contents have changed or to compare two files for exact equality.

Because md5sum reads the file data, it only validates content, not file attributes.

<code>cp -a /etc/fstab /tmp/fstab
cp -a /etc/fstab /tmp/fstab1</code>

Compute checksums of the copied files:

<code>md5sum /tmp/fstab /tmp/fstab1
a612cd5d162e4620b442b0ff3474bf98  /tmp/fstab
a612cd5d162e4620b442b0ff3474bf98  /tmp/fstab1</code>

The identical MD5 values indicate the files are exactly the same.

Saving the output to a file allows later verification with the

-c

option, which checks the current content against the stored checksums. Changes in permissions or attributes do not affect the MD5 value.

<code>md5sum /tmp/fstab /tmp/fstab1 > /tmp/fs.md5sum
md5sum -c /tmp/fs.md5sum
/tmp/fstab: OK
/tmp/fstab1: OK</code>

If a file is modified, the verification will fail:

<code>echo aaa >> /tmp/fstab1
md5sum -c /tmp/fs.md5sum
/tmp/fstab: OK
/tmp/fstab1: FAILED
md5sum: WARNING: 1 of 2 computed checksums did NOT match</code>

Additional options for

md5sum -c

include:

--quiet : suppress output for files that pass verification. --status : produce no output; exit status indicates success (0) or failure (1).

These options enable scripting to batch‑verify many files efficiently.

operationsLinuxshell scriptchecksumfile integritymd5sum
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.