Skip to content

Instantly share code, notes, and snippets.

@eriksimonic
Created June 29, 2015 10:22
Show Gist options
  • Save eriksimonic/e1d05a9f9be328d2e62c to your computer and use it in GitHub Desktop.
Save eriksimonic/e1d05a9f9be328d2e62c to your computer and use it in GitHub Desktop.
Copy only differing files from one location to another location. (A|B = B-A)
#!/bin/bash
SOURCE=source/
DESTINATION=destination/
DESTINATION_DIFF=destination_diff/
DIFF_FILE=differences.txt
DIFF_FILE_TMP=differences_tmp.txt
diff -bBqTrqN $SOURCE $DESTINATION >$DIFF_FILE
sed 's/Files //' $DIFF_FILE > $DIFF_FILE_TMP
sed 's/ and .*$//' $DIFF_FILE_TMP > $DIFF_FILE
rm $DIFF_FILE_TMP
rsync -av --files-from=$DIFF_FILE ./ $DESTINATION_DIFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment