Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Created November 28, 2012 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecthegeek/4158419 to your computer and use it in GitHub Desktop.
Save alecthegeek/4158419 to your computer and use it in GitHub Desktop.
Compare two directories when you have an old tool chain (no diff -q)
#!/bin/ksh
# Compare 2 directories for differences (e.g. current release and new release)
CURRENT=$1 ; shift
NEW=$1; shift
CURRENTDIFFFILE=/tmp/$(echo $CURRENT | sed -e 's/[/.][/.]*/_/g')
NEWDIFFFILE=/tmp/$(echo $NEW | sed -e 's/[/.][/.]*/_/g')
# File pattens not to be included in compare
cat << 'EOF' > /tmp/patternFile
^.git/
^.*\.log
^logs/.*
^.*\.tmp
^.*\.err
EOF
for i in $CURRENT $NEW ; do
cd $i
# cut removed ./ that find puts at start of path name
find . -type f -print |cut -b3- |egrep -v -f /tmp/patternFile | sort > /tmp/$(echo $i | sed -e 's/[/.][/.]*/_/g')
cd -
done
echo New files
comm -13 $CURRENTDIFFFILE $NEWDIFFFILE
echo
echo Deleted files
comm -23 $CURRENTDIFFFILE $NEWDIFFFILE
echo
echo files that are different
# xargs has limitations so must pipe into a second shell
comm -12 $CURRENTDIFFFILE $NEWDIFFFILE | xargs -i echo cmp -s \"$CURRENT/{}\" \"$NEW/{}\" \|\| echo {} changed | sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment