Skip to content

Instantly share code, notes, and snippets.

@zhangyoufu
Created September 14, 2025 08:05
Show Gist options
  • Select an option

  • Save zhangyoufu/67a50d198fbd3199c17a76a16651a650 to your computer and use it in GitHub Desktop.

Select an option

Save zhangyoufu/67a50d198fbd3199c17a76a16651a650 to your computer and use it in GitHub Desktop.
Calculate multiple checksum for a single file
#!/bin/bash
echo -n 'Size: '
if [[ $OSTYPE == darwin* ]]; then
stat -f %z "$1"
else
stat -c %s "$1"
fi
(tee < "$1" > /dev/null \
>(echo "MD5: $(md5sum | cut -d' ' -f1)" >&3) \
>(echo "SHA-1: $(sha1sum | cut -d' ' -f1)" >&3) \
>(echo "SHA-256: $(sha256sum | cut -d' ' -f1)" >&3) \
>(echo "SHA-512: $(sha512sum | cut -d' ' -f1)" >&3) \
) 3>&1 | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment