From the manpage of rsync
–remove-source-files
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.
-
Does it mean files on the sending side that are either part of the transfer or duplicated on the receiving side?
-
Can I also remove directories on the sending side?
Note that you should only use this option on source files that are quiescent.
- What does "source files that are quiescent" mean?
If you are using this to
move files that show up in a particular directory over to another host, make sure that the finished
files get renamed into the source directory, not directly written into it, so that rsync can't possibly
transfer a file that is not yet fully written.
- What does this mean?
If you can't first write the files into a different directory,
you should use a naming idiom that lets rsync avoid transferring files that are not yet finished (e.g.
name the file "foo.new" when it is written, rename it to "foo" when it is done, and then use the
option –exclude='*.new' for the rsync transfer).
- What does this mean?
Starting with 3.1.0, rsync will skip the sender-side removal (and output an error) if the file's size or
modify time has not stayed unchanged.
- What does this mean?
Thanks.
Best Answer
Q: Does it mean files on the sending side that are either part of the transfer or duplicated on the receiving side?
Q: Can I also remove directories on the sending side?
--remove-source-files
then issue the commandfind <source_directory> -type d -empty -delete
ORfind <source_directory> -type l -type d -empty -delete
(to include symlinks in the deletion)(Was:
)--remove-source-files
then issue the commandrm -rf <source_directory>
WARNING:
As mentioned in OrangeDog's comment, the
rm -rf
suggestion is unsafe. Specifically, any files that were for any reason not transferred (file changed between building the transfer list and starting to actually transfer that file, receiving side ran out of disk space, network connection dropped, etc.) will be left untouched in the source directory by rsync — but after yourrm -rf
invokation they're just gone. Thefind
command above will recursively delete the empty source tree if all the source files have been successfully transferred and removed, but will leave alone any remaining files (and their containing directories, of course).Q: What does "source files that are quiescent" mean?
Q: If you are using this to move files that show up in a particular directory over to another host, make sure that the finished files get renamed into the source directory, not directly written into it, so that rsync can't possibly transfer a file that is not yet fully written. What does this mean?
Q: If you can't first write the files into a different directory, you should use a naming idiom that lets rsync avoid transferring files that are not yet finished (e.g. name the file "foo.new" when it is written, rename it to "foo" when it is done, and then use the option --exclude='*.new' for the rsync transfer). What does this mean?
Q: Starting with 3.1.0, rsync will skip the sender-side removal (and output an error) if the file's size or modify time has not stayed unchanged. What does this mean?