Tricky rsync question

Discussion in 'Command Line' started by Rob, Feb 27, 2013.

  1. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    193
    Trophy Points:
    43
    Here's a good scenario that I just thought of..

    You have an existing folder with a bunch of files and directories in it. Let's call it /path/to/dest/

    You have another folder with a different bunch of files and directories in it.. lets call that /path/to/source/

    You rsync everything from /path/to/source/ into /path/to/dest/

    Then, you realize you really wanted to put things into /path/to/dest2/ instead...

    Can you tell rsync to remove everything in /path/to/dest/ that matches /path/to/source/? :)

    I almost ran into this yesterday and caught myself before I did the rsync..

  2. grash

    grash New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    You could do something like this:

    Step1 - ls /path/to/source/ > exclude.txt

    Step2 - rsync -av --delete --exclude-from=exclude.txt /path/to/source/ /path/to/dest/

Share This Page