Skip to content

Instantly share code, notes, and snippets.

@mimizone
Created May 26, 2023 04:49
Show Gist options
  • Save mimizone/10ac334cb7fac099c00dac34a54a9d79 to your computer and use it in GitHub Desktop.
Save mimizone/10ac334cb7fac099c00dac34a54a9d79 to your computer and use it in GitHub Desktop.
compare the checksum of all files with the same name in 2 different folders
#!/bin/bash
CERROR='\033[0;31m' #Error color
COK='\033[0;32m' #Error color
NC='\033[0m' # No Color
IFS=$'\n'
offset=$(( ${#1} + 1))
fnames=`find ${1} -type file -not -path '*/.*'`
for f in ${fnames}
do
s1=`shasum -a 256 ${f} | awk '{ print $1 }'`
s2=`shasum -a 256 ${2}/${f:$offset} | awk '{ print $1 }'`
if [ "$s1" != "$s2" ]; then
printf "${CERROR}ERROR \\t${NC}${f:$offset}\n"
else
printf "${COK}OK \\t${NC}${f:$offset}\n"
fi
done
@mimizone
Copy link
Author

more precisely, for all files in the first folder and its subfolders, it checks in the second directory if any other file with the same name and path as in the one in the first folder has the same checksum or not and displays a message OK or ERROR respectively with the path/filename of the file.
OK is green. ERROR is red.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment