Linux / Unix rsync: Delete Source File After Transfer

Linux / Unix rsync: Delete Source File After Transfer

To delete the source file after transferring it with rsync, you can use the --remove-source-files option.

This option tells rsync to delete the source file after transferring it to the destination. It is useful when you want to move files from one location to another, rather than copying them.

Here is an example of how to use the --remove-source-files option with rsync:

rsync -av --remove-source-files source/ destination/
Sourc‮al.www:e‬utturi.com

This command will transfer all files from the source/ directory to the destination/ directory, and delete the source files after transferring them. The -a option tells rsync to preserve the file attributes and permissions, and the -v option enables verbose output.

Keep in mind that the --remove-source-files option only works if the source and destination directories are on the same filesystem. If the source and destination are on different filesystems, rsync will copy the files rather than moving them, and the source files will not be deleted.

You can also use the --remove-sent-files option, which is similar to --remove-source-files but only deletes files that were successfully transferred. This can be useful if you want to ensure that only transferred files are deleted, rather than deleting all source files regardless of the transfer status.

For example, you can use the following command to delete only transferred files:

rsync -av --remove-sent-files source/ destination/

Keep in mind that using the --remove-source-files or --remove-sent-files options can be dangerous, as it can result in data loss if the transfer is interrupted or fails. Make sure to use these options with caution and backup your data before using them.

Created Time:2017-10-29 22:08:58  Author:lautturi