-
-
Save Sythelux/bb37d4360894383d87d049cb39aaef59 to your computer and use it in GitHub Desktop.
my move is supposed to copy source to target recursively. if target already exists it checks file size. if size is the same delete old one. if size is different keep old and new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# my move is supposed to copy source to target recursively. if target already exists it checks file size | |
#if size is the same delete old one | |
#if size is different keep old and new | |
source=$1 | |
target=$2 | |
IFS=$'\n' | |
if [ -d "$source" ]; then | |
# echo "$source is a dir" | |
find "$source" -type f -exec $0 "{}" "$target" \; | |
find . -type d -empty -delete | |
else | |
targetFile=$target/${source#*/} | |
target=${targetFile%/*} | |
#echo "targetfile:'$targetFile', target:'$target'" | |
#echo "mkdir --parents $target" | |
mkdir --parents "$target" | |
if [ -f "$targetFile" ]; then | |
wcSource=`wc -c < "$source"` | |
wcTarget=`wc -c < "$targetFile"` | |
if [ "$wcSource" == "$wcTarget" ]; then | |
#echo "$wcSource == $wcTarget" | |
rm "$source" | |
else | |
echo "$wcSource != $wcTarget" | |
fi | |
else | |
mv "$source" "$target" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment