I'm trying to write a bash shell script to sync content on two different paths.
The algorithm I'm striving for consists of the following steps
- given two full (as opposed to relative) paths
- recursively compare files (whose filename optionally may have basename and suffix) in corresponding directories of both paths
- if either corresponding directories or files are not present, then copy each file (from the path with the folder) to the other corresponding folder.
I've figured out steps 1 and 2 which are
OLD_IFS=$IFS
# The extra space after is crucial
IFS=\
for old_file in `diff -rq old/ new/ | grep "^Files.*differ$" | sed 's/^Files \(.*\) and .* differ$/\1/'`
do
mv $old_file $old_file.old
done
IFS=$OLD_IFS
Thanks.