I want to synchronize 2 codebases. The below command is working great, except that it doesn't account for one use case that I have with 2 directories named test in different locations:
- /test/
- /start/test/
$ rsync -avCz --delete-before --progress --exclude=test /tmp/codebase/ .
What I want to do is to exclude the /test directory completely from the rsync but I do want /start/test to be rsync'ed.
I'd prefer not to have to come up with a static TXT file that I should pass as an argument to rsync. Is there any way to achieve this otherwise? Playing with –include VS –exclude and a trailing slash (–exclude=test/) didn't work as anticipated for me.
Best Answer
You can use a leading
/
to match only in the root of the transfer. Try this:Here is the man page snippet for the leading
/
:And for the trailing
/
:Update
I am guessing from you comments that you are also looking for the
--delete-excluded
option.