hashfolder.sh (613B)
1 #!/usr/bin/env bash 2 3 # Script to get sha256/sha512 hashes of all files in a directory 4 5 if [[ "$1" == "" ]]; then 6 echo "Usage: ./hashfolder.sh [-l] folder" 7 echo " -l for sha512" 8 exit 9 fi 10 11 hash_command="sha256sum" 12 input_folder="$1" 13 if [[ "$1" == "-h" ]]; then 14 echo "Usage: hashfolder [-l] folder/ (-l for sha512 instead of sha256)" 15 elif [[ "$1" == "-l" ]]; then 16 hash_command="sha512sum" 17 input_folder="$2" 18 fi 19 20 # There is probably a better way of doing this 21 oldIFS="$IFS" 22 IFS=$'\n' 23 filesA=( $(find "$input_folder" -type f | sort) ) 24 IFS="$oldIFS" 25 26 for fileA in "${filesA[@]}"; do 27 "$hash_command" "$fileA" 28 done