#!/bin/bash # This script calculates a sha256sum over all files in a dirextory including its subdirectories # Length of the sha256 hash. Adapt when changing hash algorithm hashlen=64 if [[ -z $1 ]]; then echo "Usage: $0 " exit -1 fi if [[ ! -d "$1" ]]; then echo "Specified path: $1 is not a directory" exit -2 fi search_dir="$1" filelist=() while IFS= read -d $'\0' -r file ; do filelist=("${filelist[@]}" "$file") done < <(find "$search_dir" -type f -print0 | sort -z) echo "Found ${#filelist[@]} files" # Calculate shasums over all files shasum=`for file in "${filelist[@]}"; do sha256sum "$file" | head -c $hashlen echo "" done | sha256sum | sed 's/\s-//'` echo "$shasum"