Skip to content

Instantly share code, notes, and snippets.

@AlonsoFloo
Created September 19, 2018 10:06
Show Gist options
  • Save AlonsoFloo/9847957015cdd48a64106887b3bfdc11 to your computer and use it in GitHub Desktop.
Save AlonsoFloo/9847957015cdd48a64106887b3bfdc11 to your computer and use it in GitHub Desktop.
Checksum utility for BASH
if [ "$#" -lt 1 ]; then
echo "Usage : checksum [FILE_PATH..]"
return
fi
for f in "$@"
do
if [ -f $f ]; then
sha=`/usr/bin/openssl sha1 -sha ${f} | tr -s "=" | cut -d ' ' -f 2`
sha1=`/usr/bin/openssl sha1 -sha1 ${f} | tr -s "=" | cut -d ' ' -f 2`
sha256=`/usr/bin/openssl sha1 -sha256 ${f} | tr -s "=" | cut -d ' ' -f 2`
sha512=`/usr/bin/openssl sha1 -sha512 ${f} | tr -s "=" | cut -d ' ' -f 2`
md5=`/usr/bin/openssl sha1 -md5 ${f} | tr -s "=" | cut -d ' ' -f 2`
echo "Checksum for file ${f}"
echo "MD5 : ${md5}"
echo "SHA : ${sha}"
echo "SHA1 : ${sha1}"
echo "SHA256 : ${sha256}"
echo "SHA512 : ${sha512}"
else
echo "File ${f} does not exist"
fi
echo "-----------------------------------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment