Created
August 21, 2021 15:55
-
-
Save paullaffitte/23561c9bd3c435891dde9e376abc3be2 to your computer and use it in GitHub Desktop.
Recursively compare files
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
#! /bin/bash | |
if [[ $# != 2 ]]; then | |
echo "usage: cmprec <source1> <source2>" | |
exit 1 | |
fi | |
SOURCE1=$1 | |
SOURCE2=$2 | |
echo "Preparing filenames list..." 1>&2 | |
filenames="$(( | |
cd "$SOURCE1"; find -type f; cd - > /dev/null | |
cd "$SOURCE2"; find -type f; cd - > /dev/null | |
) | sort | uniq)" | |
echo "List ready, starting to compare files!" 1>&2 | |
total=$(echo "$filenames" | wc -l) | |
i=0 | |
echo "$filenames" | while IFS="\n" read -r filename; | |
do | |
filename=${filename:2} | |
if cmp "$SOURCE1/$filename" "$SOURCE2/$filename" --quiet; then | |
echo "OK $filename" | |
else | |
echo "DIFF $filename" | |
fi | |
i=$((i+1)) | |
percent=$(echo "scale=2; $i * 100 / $total" | bc -l) | |
echo -ne "$i/$total files ($percent%)\r" 1>&2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment