I use rsync to copy directories including files, with --remove-source-files I let rsync delete source files. Unfortunately it doesn't delete directories so I would like to delete all empty directories under SOURCE1 and SOURCE2. The find -exec rmdir command does this but unfortunately it also deletes the SOURCE directories itself
Copy.sh
SOURCE1="/mnt/download/transmission/complete/"
SOURCE2="/mnt/download/sabnzbd/completed/"
sudo rsync --remove-source-files --progress --ignore-existing -vr /mnt/download/transmission/complete/ /mnt/dune/DuneHDD_1234
sudo rsync --remove-source-files --progress --ignore-existing -vr /mnt/download/sabnzbd/completed/ /mnt/dune/DuneHDD_1234
find $SOURCE1 -not -name "complete" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty -p \{\} \;
find $SOURCE2 -not -name "completed" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty -p \{\} \;
I also tried the following code
*
find $SOURCE1 -mindepth 2 -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty -p \{\} \;
find $SOURCE2 -mindepth 2 -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty -p \{\} \;
And without
*
find $SOURCE1 -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty -p \{\} \;
find $SOURCE2 -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty -p \{\} \;
I could add a mkdir test and change SOURCE1 to "/mnt/download/transmission/complete/test" and this way it always deletes the directory that I just created but I would like to do it the proper way
Example: I created 6 directories:
test10/
test10/test11/
test10/test11/test12/
test10/test11/test12/test
test1/
test1/test2/
test1/test2/test3/
test1/test2/test3/test
After running copy.sh I end up with perfectly copyed directories and files (test1/test2/test3/test and test10/test11/test12/test) on destination and deleted directories and files on source INCLUDING source ($SOURCE1 and $SOURCE2) itself.
Is there a way to tell find to exclude the source directory itself? In other words: Everything UNDER the folowing directories shoud be deleted but not the directories themselves:
SOURCE1="/mnt/download/transmission/complete/"
SOURCE2="/mnt/download/sabnzbd/completed/"