Linux / Unix rsync: Delete Source File After Transfer

by on September 14, 2012 · 2 comments· last updated at 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?

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsrsync

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
 


You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 2 comments… read them below or add one }

1 Vijay September 14, 2012 at 5:17 am

This is one of the good aspect of rsync. Additionally, you can use this too --delete-after.

Reply

2 Jalal Hajigholamali September 15, 2012 at 4:54 am

Hi,
Very nice article….
thanks

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , ,

Previous Faq:

Next Faq: