Skip to content

Instantly share code, notes, and snippets.

@Sythelux
Last active August 15, 2018 20:05
Show Gist options
  • Save Sythelux/bb37d4360894383d87d049cb39aaef59 to your computer and use it in GitHub Desktop.
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
#!/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