sha256sum Cheatsheet
Quick reference for generating and verifying SHA-256 and MD5 checksums with sha256sum, md5sum, and related Linux hash commands
The sha256sum command prints and checks SHA-256 checksums, and md5sum does the same for MD5 digests. This cheatsheet covers generating checksums, verifying SHA256SUMS files, scripting flags, and the wider family of Linux hash tools.
Generate Checksums
Print a digest for one or more files.
| Command | Description |
|---|---|
sha256sum file.iso | Print the SHA-256 digest of a file |
sha256sum file1 file2 | One digest line per file |
sha256sum *.tar.gz > SHA256SUMS | Save digests to a checksum file |
printf '%s' "text" | sha256sum | Hash a string from stdin |
find dir/ -type f -exec sha256sum {} + | Hash every file in a directory tree |
Verify Checksums
Check files against a checksum list with -c.
| Command | Description |
|---|---|
sha256sum -c SHA256SUMS | Verify every file in the list |
sha256sum -c --ignore-missing SHA256SUMS | Verify only the files that are present |
grep file.iso SHA256SUMS | sha256sum -c - | Verify a single file from a larger list |
echo "DIGEST file.iso" | sha256sum -c - | Compare against a pasted digest (two spaces) |
sha256sum -c --quiet SHA256SUMS | Print failures only, skip OK lines |
Useful Options
Flags shared by sha256sum, md5sum, and the other GNU hash tools.
| Option | Description |
|---|---|
-c, --check | Read digests from a file and verify them |
--quiet | Do not print OK for verified files |
--status | Print nothing; report via exit status only |
--warn | Warn about improperly formatted lines |
--strict | Exit non-zero when a line is badly formatted |
--ignore-missing | Skip listed files that do not exist |
--tag | BSD-style output, SHA256 (file) = digest |
-b, --binary | Mark files with * in the output |
-z, --zero | End output lines with NUL instead of newline |
Scripting and Exit Codes
Automate checks in scripts and CI jobs.
| Command | Description |
|---|---|
sha256sum -c --status SHA256SUMS && echo ok | Branch on the verification result |
sha256sum -c SHA256SUMS || exit 1 | Abort a script on any mismatch |
[ "$(sha256sum < f)" = "$(sha256sum < g)" ] | Compare two files by digest |
sha256sum file | cut -d' ' -f1 | Extract the bare digest value |
Other Hash Commands
Same interface, different algorithms.
| Command | Description |
|---|---|
md5sum file | 128-bit MD5; corruption checks only, not security |
sha1sum file | 160-bit SHA-1; legacy, avoid for new uses |
sha512sum file | 512-bit SHA-2 digest |
b2sum file | BLAKE2; fast modern alternative |
cksum -a sha256 file | Unified hash tool in newer coreutils |
Troubleshooting
Quick checks for common verification problems.
| Issue | Check |
|---|---|
| Digest mismatch on a download | Re-download, ideally from a different mirror |
no properly formatted checksum lines found | Fix CRLF endings with dos2unix, check the file format |
No such file or directory with -c | Run from the directory that holds the listed files |
| Every other release fails as missing | Add --ignore-missing to scope the check |
| Digest source is untrusted | Verify the GPG signature on the checksum file itself |
Related Guides
Full walkthroughs for checksums and signing.
| Guide | Description |
|---|---|
| Verify a Checksum in Linux | Full sha256sum and md5sum tutorial |
| Encrypt and Decrypt Files with GPG | Work with GPG keys and signatures |
| wget Command Examples | Download files and checksum lists |