Linux / Unix rsync: Delete Source File After Transfer

Posted on in Categories last updated September 14, 2012

I would like to move all desktop:~/Downloads/*.avi files from my desktop to laptop:~/Download/ using rsync. How do I delete source file after successful transfer is done using rsync command under BSD/Unix/Linux/Apple OS X operating systems?


You need to pass the --remove-source-files option to the rsync command. It 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. Do not pass the --delete option to rsync command as it delete extraneous files from destination directory.

Delete source after successful transfer using rsync

The syntax is:

rsync --remove-source-files -options /path/to/src/ /path/to/dest
rsync --remove-source-files -options /path/to/src/ computerB:/path/to/dest
rsync --remove-source-files -av /path/to/src/*.avi computerB:/path/to/dest

You can always perform a trial run with no changes made using --dry-run option:

rsync --dry-run --remove-source-files -azv /path/to/Download/*.avi laptop:~/Download

If you like output run the final command without --dry-run option:

rsync --remove-source-files -azv /path/to/Download/*.avi laptop:~/Download

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

9 comment

  1. this is to delete source file what would be the command if we want to delete an old file from destination after rsync complete
    my scenario is
    rsync -e ‘ssh -p 22’ -Cavz [email protected]_computer:/home/user/dbbackup /home/user/backup/
    but this command rsync new file but also keep the old file in my home/user//backup/
    I want to remove the old file just want newly copied file.

    Please help.

    1. Tyee Cambron, the “-options” perimeter is not an actual perimeter. The author has added that in to show that that is where you put your options, such as avz. So “-options” would be replaced by “-avz”

Leave a Comment