regexghost-dotfiles

My dotfiles and scripts
git clone git@git.regexghost.com/regexghost-dotfiles.git
Log | Files | Refs | README

cmpfolder.sh (633B)


      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 if [[ "$3" == "-o" ]]; then
     16 	for fileA in "${filesA[@]}"; do
     17 		fileName=$(basename "$fileA")
     18 		fileToCmp="${2}/${fileName}"
     19 		cmp "$fileA" "$fileToCmp"
     20 	done
     21 	exit
     22 fi
     23 
     24 index=0
     25 for fileA in "${filesA[@]}"; do
     26 	fileToCmp="${filesB[index]}"
     27 	indexA=$((index+1))
     28 	index="$indexA"
     29 	cmp "$fileA" "$fileToCmp"
     30 done