sha256sum and md5sum Commands: Verify File Integrity in Linux
When you download an ISO image, a backup archive, or a large release tarball, there is no easy way to tell by looking whether the file arrived intact. A single flipped bit can break a boot image or turn a compressed archive into junk, and a compromised mirror can serve a tampered file that looks legitimate. The fix is to compare a cryptographic fingerprint of the file against a value the publisher has signed or posted somewhere you trust.
This guide shows how to use sha256sum and md5sum to generate, compare, and verify checksums on Linux, and when to use each one.
sha256sum and md5sum Syntax
Both commands follow the same form:
sha256sum [OPTIONS] [FILE]...
md5sum [OPTIONS] [FILE]...Without options, each command prints a hex digest followed by two spaces and the file name. Pass -c to verify files against a list of previously generated checksums.
sha256sum vs md5sum
The two tools do the same job: they read a file and print a fixed-length fingerprint. The difference is the algorithm and, by extension, how safe the result is against intentional tampering.
md5sum uses the MD5 algorithm and produces a 128-bit digest. MD5 is fast but has been broken for years: it is possible to construct two different files that share the same MD5 hash. Treat it as a checksum for accidental corruption only, not for authenticity or security.
sha256sum uses SHA-256 from the SHA-2 family and produces a 256-bit digest. It is the default choice for verifying downloads, release artifacts, and anything where the threat model includes a malicious middle party. Most Linux distributions publish SHA256SUMS files next to their ISO images for exactly this reason.
When in doubt, use sha256sum. Reach for md5sum only when a publisher provides MD5 values and nothing stronger, or when you need quick parity checks between known-good files.
Generating a Checksum for a File
To produce a SHA-256 digest for a single file, pass it as an argument:
sha256sum ubuntu-24.04.2-desktop-amd64.iso5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931 ubuntu-24.04.2-desktop-amd64.iso
The output is one line: the hex digest, two spaces, and the file name. The same file always produces the same digest, so you can run the command again after a copy or a download and compare the values by eye.
md5sum behaves the same way:
md5sum ubuntu-24.04.2-desktop-amd64.iso2e3720b76b2f9f96edc43ec4d87d7d52 ubuntu-24.04.2-desktop-amd64.iso
Notice that the MD5 digest is shorter. That is the 128-bit hash encoded in 32 hex characters, compared with 64 hex characters for SHA-256.
Generating Checksums for Multiple Files
Both commands accept any number of file arguments and print one line per file:
sha256sum *.tar.gzb2b09c1e04b2a3a4c5d6e7f890123456789abcdef0123456789abcdef01234567 backup-2026-04-01.tar.gz
c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8 backup-2026-04-08.tar.gz
To save the output to a checksum file that you can share or verify later, redirect it:
sha256sum *.tar.gz > SHA256SUMSThe resulting SHA256SUMS file can be published alongside the archives, and anyone who downloads them can run a single command to confirm that their copy matches.
Verifying a File Against a Known Checksum
The most common task is to check that a download matches the digest the publisher posted. Distributions usually ship a SHA256SUMS file that lists every release file and its digest. Change into the directory that holds both the archive and the checksum file, then pass -c:
sha256sum -c SHA256SUMSubuntu-24.04.2-desktop-amd64.iso: OK
ubuntu-24.04.2-live-server-amd64.iso: OK
sha256sum reads each line of SHA256SUMS, recomputes the digest for the named file, and prints OK when they match. Any line whose file is missing or whose digest differs prints a clear error and causes the command to exit with a non-zero status, which is convenient in scripts.
When you only care about one file out of many, grep the relevant line into the check:
grep "ubuntu-24.04.2-desktop-amd64.iso" SHA256SUMS | sha256sum -c -The trailing - tells sha256sum to read the checksum list from standard input. This keeps the verification scoped to a single file without creating a second checksum file.
Comparing a File to a Published Digest
Sometimes the publisher does not provide a full SHA256SUMS file but instead shows a single digest on a release page. You can compare it directly without creating a file:
echo "5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931 ubuntu-24.04.2-desktop-amd64.iso" | sha256sum -c -ubuntu-24.04.2-desktop-amd64.iso: OK
The key detail is the double space between the digest and the file name. That is the exact format sha256sum produces and expects, and a single space will cause the check to fail.
Quiet and Warn Modes
During an automated check, the per-file OK lines can be noisy. The --quiet option suppresses successful lines so only failures appear:
sha256sum -c --quiet SHA256SUMSIf every file passes, the command prints nothing and exits with status 0. If a file fails, you see a single failure line and a non-zero exit status, which fits well in a CI job or a backup script.
To flag lines in a checksum file that are not formatted correctly, add --warn. This is helpful when the file was assembled by hand and you want to be sure every entry parses.
Common Options
The flags below are the ones you are likely to use day to day:
-
-c,--check- Read digests from a file and verify each one. -
-b,--binary- Mark files as binary in the output (default on Linux). -
-t,--text- Read files in text mode (rare on Linux, kept for portability). -
--quiet- SuppressOKlines when checking. -
--status- Print nothing; rely on the exit status alone. -
--ignore-missing- Skip files listed in the digest file that are not present. -
--tag- Output BSD-style tagged format, useful when mixing hash algorithms.
md5sum accepts the same flags, which makes it easy to swap one command for the other when the algorithm changes.
Quick Reference
| Command | Description |
|---|---|
sha256sum file.iso |
Generate a SHA-256 checksum for one file |
md5sum file.iso |
Generate an MD5 checksum for one file |
sha256sum *.tar.gz > SHA256SUMS |
Save checksums for multiple files |
sha256sum -c SHA256SUMS |
Verify files against a checksum list |
| `grep “file.iso” SHA256SUMS | sha256sum -c -` |
sha256sum -c --quiet SHA256SUMS |
Show only failures during verification |
Verifying a Download End to End
Putting the pieces together, a typical download check looks like this:
wget https://releases.ubuntu.com/24.04/ubuntu-24.04.2-desktop-amd64.iso
wget https://releases.ubuntu.com/24.04/SHA256SUMS
sha256sum -c --ignore-missing SHA256SUMSThe --ignore-missing flag keeps the check focused on the file you actually downloaded instead of failing on every other release listed in SHA256SUMS.
For full confidence, also verify the signature on SHA256SUMS itself using the publisher’s GPG key. A digest is only as trustworthy as the source you got it from, so a signed checksum file closes the loop.
Troubleshooting
Checksum mismatch on a freshly downloaded file
Re-download the file, ideally from a different mirror. The most common cause is a truncated transfer or a network error. If the second download still fails, the file on the mirror may be stale or tampered with, and you should report it to the project.
No such file or directory when running with -c
The names in the checksum file are resolved relative to the current directory. Change into the directory that holds the files, or edit the checksum file to use paths that match where the files live.
improperly formatted checksum line warnings
A single space between the digest and the file name instead of two, trailing whitespace, or Windows line endings will all trip the parser. Run dos2unix on the file or recreate it with sha256sum > SHA256SUMS to reset the format.
The MD5 digest matches but you still do not trust the file
You are right to be cautious. MD5 collisions are practical, so match an MD5 against accidental corruption only. Ask the publisher for a SHA-256 digest or a signed checksum file.
FAQ
Which is faster, sha256sum or md5sum?md5sum is faster, sometimes noticeably so on large files. The speed difference rarely matters on modern hardware, and it is not a good reason to pick MD5 over SHA-256 for security-sensitive checks.
Can I use sha256sum on a directory?
Not directly. Hash tools operate on files. To produce a digest that represents an entire directory, pipe a deterministic listing such as find ... -type f -print0 | sort -z | xargs -0 sha256sum through another sha256sum.
Where do I find the expected digest for a Linux distro ISO?
Every major distribution publishes a SHA256SUMS or SHA512SUMS file on its download page, usually along with a detached GPG signature. Prefer those files over digests shown in third-party blog posts.
Is sha256sum available by default on Linux?
Yes. Both sha256sum and md5sum ship with the GNU coreutils package, which is installed on every mainstream Linux distribution.
Conclusion
sha256sum should be the default for verifying downloads and backups, with md5sum reserved for quick corruption checks when the publisher provides nothing stronger. When you pair a SHA-256 digest with a signed checksum file and a trusted key, you can answer the question that matters most: did I get the file the publisher actually shipped?










