Motivation
Be able to check the sha256 sums on the files downloaded from internet
Installation
- Copy the script file into a
Scriptsfolder in your Home directory (at the same level asDocumentsDownloadsetc.) - Make the file executable
sudo chmod a+x hash-check_sha256 - Add the
Scriptsinto path in your~/.bashrcfile by adding a following line at the end
PATH="$HOME/Scripts:$PATH"
- Add the alias
hash-checkinto the aliases into the~/.bashrcor~/.bash_aliasesfile using following command
echo "alias hash-check=hash-check_sha256" >> ~/.bash_aliases
How to use it
- Downolad the file which hash sum you want to check
- Copy the sha256sum into clipboard
- Type
hash-check <file-name> <sha256sum from clipboard>
Script
File to download
Code
#!/bin/bash
[ "$#" -ne 2 ] && echo "Usage: $0 <filename> <expected_hash>" && exit 1
FILE="$1"
EXPECTED="$2"
[ ! -f "$FILE" ] && echo "Error: File not found!" && exit 1
CALCULATED=$(sha256sum "$FILE" | awk '{print $1}')
echo "Expected: $EXPECTED"
echo "Calculated: $CALCULATED"
[ "$CALCULATED" = "$EXPECTED" ] && echo "Hash matches!" || echo "Hash does NOT match!"