Working with checksums on MacOS and Linux

Algorithm MacOS Linux
MD5 md5 md5sum
SHA1 shasum -a 1 sha1sum
SHA256 shasum -a 256 sha256sum
SHA512 shasum -a 512 sha512sum

With no FILE, or when FILE is -, read standard input. Attention echo produces a trailing newline character which is hashed too, e.g. echo -n "Example string" | md5sum -.

Checksums can be written to a file as follows:

sha1sum test.txt test2.txt > files.sha1

And can be validated by:

sha1sum -c files.sha1

Helper functions

alias sha256sum='shasum --algorithm 256'

# or

sha256() { echo -n "$*" | shasum -a 256 }