Directory Sync with a Subdirectory to Ignore

2019-08-29 07:52发布

问题:

I need to do a directory sync e.g. from /dir-a/ to /dir-b/ (always in this direction). However, there are two requirements:

  1. There is a particular subdirectory /dir-a/.dont-copy/ (yes, started with a .) that I should ignore. That is, /dir-a/.dont-copy/ should always stay in /dir-a/, never move.
  2. Files / directories in /dir-b/ that don't exist in /dir-a/ should be deleted.

How would I do this using command-line tools (ideally, on Mac OSX)? Thanks beforehand for your help!

回答1:

try:

$ rsync -avz --exclude=.dont-copy --delete dir-a/ dir-b

Note the trailing slash on dir-a. If you omit that, you will get dir-b/dir-a.