newdeveloper
newdeveloper

Reputation: 702

Rsync delete argument is not removing

I am rsyncing directories rsync --delete /home/pi/folder1/*.png /home/pi2/folder2/ When i run the above command I am getting rsync: --delete does not work without --recursive (-r) or --dirs (-d). When I add -r rsync does not delete.
However if I rsync --delete /home/pi/folder1/ /home/pi2/folder2/ deletion works. But I can't use rsync like that because there is other data in the folder2 that I need to keep.

Upvotes: 2

Views: 2019

Answers (1)

Freddy
Freddy

Reputation: 4688

You can only delete extraneous files if you transfer a directory, but you can use --exclude to exclude all other files which are then also excluded from the deletion, e.g.

rsync -av --delete --include='*.png' --exclude='*' /home/pi/folder1/ /home/pi2/folder2

This would sync all *.png files from folder1 (but not from subfolders) to folder2 and delete extraneous *.png files in folder2 (but not from subfolders of folder2).

Options:

  • -a shortcut for -rlptgoD
  • -v increase verbosity

As always: Test this using a test destination directory before running this on your data.

Upvotes: 3

Related Questions