I want to move a folder to an other location without using mv

I use

rsync -aAXHv --remove-source-files <source> <destination>

but the source folder <source> remains without content. Is there option that removes all empty source folder?


2 Answers 2


Follow the rsync command with rm, guarded to ensure it only fires if the copy succeeds

rsync -aAXHv --remove-source-files {src} {dst} &&
    rm -rf {src}

Of course, with this combination you no longer necessarily need the --remove-source-files.


I like to do my empty folder cleanup with some sanity. I run:

find folder -type d -empty -exec rmdir {} \;

repeat as many times as necessary to recursively remove empty subfolders, and ONLY EMPTY folders will be removed (because rmdir has safety built in, and it won't remove a non-empty folder) so there's no risk of my later learning that "rsync failed to move these files and my brute force rm -fr / just nuked my only copy" ;-)

zsh protip:

repeat 15 find folder -type d -empty -exec rmdir {} \;

will take care of pretty much any empty folder stack.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .