Skip to content

Instantly share code, notes, and snippets.

@xgouchet
Last active February 16, 2024 12:32
Show Gist options
  • Save xgouchet/5b0bd67a096231e6f60b to your computer and use it in GitHub Desktop.
Save xgouchet/5b0bd67a096231e6f60b to your computer and use it in GitHub Desktop.
A shell script to perform a recursive diff between two folders
#!/bin/bash
## get the folders
folder1=$1
folder2=$2
empty="..."
# check we have two folders
if [ -z "$folder2" ]; then
echo " Missing folders to diff "
echo " Usage : "
echo " folder_diff path/to/folder1 path/to/folder2"
exit 1
fi
#IFS=$'\n'
for file in $(grep --binary-files=without-match --files-with-matches --no-messages --recursive --max-count=1 '.' "$folder1"); do
base=$(basename $file)
need_diff=`diff -q "$file" "${file/${folder1}/${folder2}}"`
if [ -z "$need_diff" ]; then
echo " - Processing file $base : no difference"
else
read -n1 -p " - Processing file $base (d to show diff, i to ignore, q to quit) " input
if [ "$input" = "q" ]; then
echo ""
exit 0
fi
echo ""
if [ "$input" = "d" ]; then
# -N : treat absent file as empty
# -w : ignore all whitespaces
# -B : ignore blank lines
colordiff -N -wB "$file" "${file/${folder1}/${folder2}}"
read -n1 -p " nothing more to report (enter to continue or q to quit) " input
if [ "$input" = "q" ]; then
echo ""
exit 0
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment