I would like to be able to transfer files from a camera memory card to my local storage, and once copied, verify that the files match between source and destination and then delete the files on the source.

Currently I am running:

rsync --update -va --progress --no-r --info=progress2 source/** destination

I am flattening the destination so only files get copied and not source directories.

What would I need to add to this command to then cleanup all files and directories from the source as long as the transfer is verified?

2 Answers 2



I googled "rsync delete from source" and found this: rsync delete files on sending side after transfer - Stack Overflow. And here's part of the description from man rsync:

       This tells rsync to remove from the sending side the files 
       (meaning non-directories) that are a part of the transfer and
       have been successfully duplicated on the receiving side.
  • Thanks @wjandrea but this only deletes the files not the directories. I effectively want to delete the directories. I suppose I could sting a non rsyn command rm-r? for the source folder? I effectively want to format the volume again ready for the camera.
    – ejnewman
    Jul 9, 2019 at 4:22
  • @ejnewman Oh, I missed that you want to delete the directories too. I think your answer has the best solution for that. :)
    – wjandrea
    Jul 9, 2019 at 13:24
  • @wjandrea - great, that solves it then! thanks for your input.
    – ejnewman
    Jul 9, 2019 at 20:50

I managed to get it to work in the end with the following:

rsync --update -va --progress --no-r --remove-source-files --info=progress2 source/** destination &&
    find source -depth -type d -empty -delete

This will use rsync to clear the synced files and then another command to clear the empty directories of the source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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