Skip to main content

sha256sum Cheatsheet

By Dejan Panovski Updated on Download PDF

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.

CommandDescription
sha256sum file.isoPrint the SHA-256 digest of a file
sha256sum file1 file2One digest line per file
sha256sum *.tar.gz > SHA256SUMSSave digests to a checksum file
printf '%s' "text" | sha256sumHash 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.

CommandDescription
sha256sum -c SHA256SUMSVerify every file in the list
sha256sum -c --ignore-missing SHA256SUMSVerify 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 SHA256SUMSPrint failures only, skip OK lines

Useful Options

Flags shared by sha256sum, md5sum, and the other GNU hash tools.

OptionDescription
-c, --checkRead digests from a file and verify them
--quietDo not print OK for verified files
--statusPrint nothing; report via exit status only
--warnWarn about improperly formatted lines
--strictExit non-zero when a line is badly formatted
--ignore-missingSkip listed files that do not exist
--tagBSD-style output, SHA256 (file) = digest
-b, --binaryMark files with * in the output
-z, --zeroEnd output lines with NUL instead of newline

Scripting and Exit Codes

Automate checks in scripts and CI jobs.

CommandDescription
sha256sum -c --status SHA256SUMS && echo okBranch on the verification result
sha256sum -c SHA256SUMS || exit 1Abort a script on any mismatch
[ "$(sha256sum < f)" = "$(sha256sum < g)" ]Compare two files by digest
sha256sum file | cut -d' ' -f1Extract the bare digest value

Other Hash Commands

Same interface, different algorithms.

CommandDescription
md5sum file128-bit MD5; corruption checks only, not security
sha1sum file160-bit SHA-1; legacy, avoid for new uses
sha512sum file512-bit SHA-2 digest
b2sum fileBLAKE2; fast modern alternative
cksum -a sha256 fileUnified hash tool in newer coreutils

Troubleshooting

Quick checks for common verification problems.

IssueCheck
Digest mismatch on a downloadRe-download, ideally from a different mirror
no properly formatted checksum lines foundFix CRLF endings with dos2unix, check the file format
No such file or directory with -cRun from the directory that holds the listed files
Every other release fails as missingAdd --ignore-missing to scope the check
Digest source is untrustedVerify the GPG signature on the checksum file itself

Full walkthroughs for checksums and signing.

GuideDescription
Verify a Checksum in LinuxFull sha256sum and md5sum tutorial
Encrypt and Decrypt Files with GPGWork with GPG keys and signatures
wget Command ExamplesDownload files and checksum lists