0

I would like to use the --delete capability of rsync to erase everyting on a destination directory.

What I am currently doing is:

rsync -zavr --delete ./input_dir_1/ user@host:dest_dir/
rsync -zavr ./input_dir_2/ user@host:dest_dir/
rsync -zavr ./input_dir_3/ user@host:dest_dir/

But in order to use rsync in a loop, is there a way to first select no input file (and use --delete to just delete everything)? Ideally I would like something like:

# Delete everything on destination dir
rsync -zavr --delete /dev/null user@host:dest_dir/

# Now iterate over all input directories (could use a for loop)
rsync -zavr ./input_dir_1/ user@host:dest_dir/
rsync -zavr ./input_dir_2/ user@host:dest_dir/
rsync -zavr ./input_dir_3/ user@host:dest_dir/

1 Answer 1

0
  1. rsync uses ssh. Why not delete directly? (Be careful not to delete the wrong directory!)
ssh user@host 'rm -rf dest_dir; mkdir dest_dir'
  1. You can use the exclude feature of rsync:
rsync -r --exclude='*' --delete-excluded / user@host:dest_dir/

Any folder will work for the source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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