Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

rsync can be coaxed into moving folders very similarly and superiorly to traditional mv with the following options:

rsync -axvvES --remove-source-files source_directory /destination/

However one thing I cannot yet seem to get it to do is to remove original directories. The --remove-source-files flag does just that, removes the source files, but not also source directories. I wish there were a --remove-source-directories flag as well, but there's not.

How can I deal with this? I suppose I can just issue an rm -fr after the move, however I'd prefer to keep the procedure all in one process vs introducing a potential for mistakes.

share|improve this question
    
What is your reason for not using mv? –  Nils Apr 28 '12 at 20:04
    
Different volumes and I need to preserve all attributes, including times. –  ylluminate Apr 28 '12 at 20:12
    
Same need here unix.stackexchange.com/q/78375/3858. –  Alix Axel Jun 7 '13 at 22:17

2 Answers 2

up vote 1 down vote accepted

I haven't found a command that does that in one go, but since rsync still performs better than rm -rf (specially if you have a very large number of directories) here are two rsync command that do a "move":

rsync -av --ignore-existing --remove-source-files source/ destination/ && \
rsync -av --delete `mktemp -d`/ source/ && rmdir source/
share|improve this answer

Why not just add rm -rf source_directory after your rsync ?

rsync -axvvES --remove-source-files source_directory /destination/ && rm -rf source_directory

Each command-line program is (idealy) made to do a specified task, and it's up to you to glue several together to accomplish more complex tasks.

share|improve this answer
2  
I think you're right. I believe I ultimately have to drill down to the bottom as well first as I cannot get caught just moving the way rsync normally does. Probably need to use find -depth. Would you have any suggestion as to a quick algorithmic approach to getting down to the bottom of the dir stack, mv'ing with rsync, rm'ing as you note, and then stepping back up the tree? –  ylluminate Apr 29 '12 at 4:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.