using rsync to delete copied files

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


On Sat, Nov 6, 2010 at 4:35 AM, Edvinas Valatka <edacval at gmail.com> 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:

#!/bin/sh
cd /dir1
for file in *; do
    if -f "$file" && -f "/dir2/$file"; then
        rm "$file"
    fi
done

..wayne..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/rsync/attachments/20101106/80532bae/attachment.html>


More information about the rsync mailing list