A checksum helps you detect whether a file’s contents have changed. On Linux, you can generate a SHA-256 checksum and later compare the file with that saved value.

Generate a checksum

In the directory containing the file, replace filename with its actual name:

sha256sum -- filename > sha256sums.txt

This saves the checksum and filename. Quote a filename containing spaces, and use a new output name if an existing checksum file must be preserved.

For SHA-512 instead:

sha512sum -- filename > sha512sums.txt

Verify a checksum

Use the command matching the saved algorithm:

sha256sum --check sha256sums.txt

or:

sha512sum --check sha512sums.txt

OK means the file matches the recorded value. FAILED means it differs; a missing or unreadable file also produces an error. Use the same file paths recorded in the checksum list.

Check downloaded files

Compare a download with a checksum obtained from a trusted publisher. Generating a checksum from an already altered file does not prove it is authentic. MD5 can detect accidental changes but is unsuitable for defending against deliberate tampering.