Skip to content

Instantly share code, notes, and snippets.

@auxiliary
Created September 9, 2017 22:32
Show Gist options
  • Save auxiliary/a06f4ca81aff67cd453008f3a0fc07e8 to your computer and use it in GitHub Desktop.
Save auxiliary/a06f4ca81aff67cd453008f3a0fc07e8 to your computer and use it in GitHub Desktop.
Better diff for comparing directories (compares file dates)
#!/bin/bash
# Better diff for directories
if [ "$#" -ne 2 ]; then
echo -e "Usage:\t./mdiff.sh <dir1> <dir2>";
exit -1;
fi;
dir1=$1
dir2=$2
oldcolor='\033[1;31m';
newcolor='\033[1;32m';
nocolor='\033[0m';
IFS=$'\n'
echo '--------------------------';
for line in `diff --brief -r $dir1 $dir2`; do
if [[ $line == *"differ" ]]; then
firstfile=`echo $line | awk '{print $2}'`;
secondfile=`echo $line | awk '{print $4}'`;
if [ $firstfile -ot $secondfile ]; then
echo -n "Files "
echo -ne ${oldcolor}$firstfile${nocolor} and ${newcolor}$secondfile${nocolor};
echo " differ"
else
echo -n "Files "
echo -ne ${newcolor}$firstfile${nocolor} and ${oldcolor}$secondfile${nocolor};
echo " differ"
fi
else
echo $line;
fi
done;
echo '--------------------------';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment