Verify a checksum

You need to validate the checksum of a file. Rather than Googling it for the hundredth time, you decide to write a note to self, in the hope it will stick this time.

Use the shasum command, with the appropriate algorithm flag.

// SHA1
$ shasum -a 1 file.txt

// SHA256
$ shasum -a 256 file.txt

// SHA512
$ shasum -a 512 file.txt

The above commands output the checksum for manual verification. You can also tell shasum to verify the checksum for you.

// If you have the SHA256 sum as a string
// Format: "<SHA256> <filename>"
$ echo "abc123 file.txt" | shasum -a 256 -c

// If you have a SHA256 file
$ echo shasum -a 256 -c "file.txt.sha256sum"

Sign up for my newsletter

A monthly round-up of blog posts, projects, and internet oddments.