-
-
Save superstes/6c5be694f56340eb2c7f90a375135f3a to your computer and use it in GitHub Desktop.
Script for recursive checksum over directory content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# NOTES: | |
# perfoms md5sum on all files in the directory, sorts them and creates an overall md5sum | |
# WARNING: the sort order & checksum will change if you do not use the same LANG/LC_ALL! | |
EXCLUDES=('dir1' 'dir2/*') | |
set -eo pipefail | |
if [[ -z "$1" ]] | |
then | |
echo "USAGE:" | |
echo " 1 > Path to base directory" | |
exit 1 | |
fi | |
set -u | |
export LANG='en_US.UTF-8' | |
export LC_ALL='en_US.UTF-8' | |
CHECK_DIR="$1" | |
cd "$CHECK_DIR" | |
exclude_args='' | |
for exc in "${EXCLUDES[@]}" | |
do | |
# shellcheck disable=SC2089 | |
exclude_args="${exclude_args} -not -path \"./${exc}\"" | |
done | |
# shellcheck disable=SC2090,SC2086 | |
find . -type f $exclude_args -print0 | sort -z | xargs -0 md5sum | sort | md5sum | cut -d ' ' -f1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment