Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Is there any option in order to keep some directories that only exists in target but doesn't exist in src? Commented Sep 28, 2021 at 8:39
  • @Jordi There is no way to tell rsync to selectively delete files and directories from the target hierarchy when they don't exist at the source. You either delete all that don't exist, or you leave them. If the files fulfill some general criteria (like having a particular filename suffix), it would be easy to go through and delete them with find afterward. You may want to ask a separate question about this if you can't find an existing query that deals with it. Commented Sep 28, 2021 at 8:44
  • --exclude will do that for you @Jordi. (Documentation - man rsync - says, "Files that are excluded from the transfer are also excluded from being deleted unless you use the --delete-excluded option or mark the rules as only matching on the sending side") Commented Sep 28, 2021 at 8:50
  • 1
    Exactly. Perhaps --exclude-from rather than --exclude, but the principle is the same: exclusion paths apply on both sides Commented Sep 28, 2021 at 9:49
  • 1
    @roaima Point taken. I won't put this into my answer as it's a follow-up topic. I'll let it stay in the comments. Commented Sep 28, 2021 at 9:51