share
Unix & Linuxrsync - delete files from source dir even nothing is copied to destination because of option "ignore-existing"
[+2] [1] o. kahn
[2020-04-16 16:24:51]
[ rsync ]
[ https://unix.stackexchange.com/questions/580497/rsync-delete-files-from-source-dir-even-nothing-is-copied-to-destination-becau ]

I have a folder on the flash drive connected to my router where i copy files that should synced to my HTPC when its starting. At start there ths little sync script is running

rsync --remove-source-files --ignore-existing -a source/ destination

This moves files to the HTPC and deletes the files on the source dir. But when the file already exists nothing is copied (there is no check for timestamps, only a file name check). But i want to delete the files in the source dir when rsync recognizes that there is already a file with the same name in the destination dir.

Can this be done with rsync?

You mean you want source/ to be empty after the rsync operation, no matter what? Why not just remove it and recreate it with rm -rf source; mkdir source after the rsync command in that case? - Kusalananda
@Kusalananda That strategy would not guarantee that the files actually exist in the destination. - forresthopkinsa
[0] [2024-03-31 11:34:31] Max Beikirch

Good question. I have a similar use case, where I used filezilla to perform my upload (as it would - in this particular case - be faster due to parallel connections) and wanted rsync to merely do verification and delete transferred source files.

I forced rsync to do that with -c. Only then, it would also delete the source files where it wouldn't do so before, with the normal skip check (based on size+time).


1