using rsync to delete copied files

Wayne Davison wayned at
Sat Nov 6 11:30:23 MDT 2010

On Sat, Nov 6, 2010 at 4:35 AM, Edvinas Valatka <edacval at> wrote:

> rsync -a -vv -i -W --remove-source-files dir1/ dir2/

You'd need to also specify --ignore-non-existing to avoid adding any new
files into dir2.  Also, -W is assumed in a local transfer, and two -v opts
is probably overkill -- two -i opts would be better.

However, the ammended command would still update the matching filenames in
dir2 if they differ in dir1 (in size or mtime), which might not have been
the original intent.  If that is a problem, writing a shell script is
probably a better idea:

cd /dir1
for file in *; do
    if -f "$file" && -f "/dir2/$file"; then
        rm "$file"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the rsync mailing list