cmpfolder.sh (772B)
1 #!/usr/bin/env bash 2 3 # Script to compare two folders to ensure they are byte for byte identical 4 5 if [[ "$2" == "" ]]; then 6 echo "Usage: ./cmpfolder.sh [-o] folder1 folder2" 7 echo " -o means compare only files in first dir" 8 exit 9 fi 10 11 IFS=$'\n' 12 filesA=( $(find "$1" -type f | sort) ) 13 filesB=( $(find "$2" -type f | sort) ) 14 15 # -o means only cmp files in first dir, to matching files in second dir 16 # Useful if first directory is an incomplete copy of the second one 17 if [[ "$3" == "-o" ]]; then 18 for fileA in "${filesA[@]}"; do 19 fileName=$(basename "$fileA") 20 fileToCmp="${2}/${fileName}" 21 cmp "$fileA" "$fileToCmp" 22 done 23 exit 24 fi 25 26 index=0 27 for fileA in "${filesA[@]}"; do 28 fileToCmp="${filesB[index]}" 29 indexA=$((index+1)) 30 index="$indexA" 31 cmp "$fileA" "$fileToCmp" 32 done