rsync – exclude only one file or directory with similar name to others

I’m using rsync to transfer a directory to another location:
rsync -av ./ /var/www/html/some_project --exclude-from=ignore_these.txt

In the current directory, I have a subdirectory named testing and a file named config.json

Deeper within the current directory, I have another subdirectory named testing and another file named config.json

I want the rsync transfer to exclude ./testing and ./config.json but include every other occurrence that may exist.

I’m using an exclusion file:

- ignore_these.txt
- testing
- config.json

Using this exclusion file, all testing and config.json items are excluded. If I prefix each with ./ then none are excluded bc. nothing ever matches ./testing etc. I cannot explicitly "include" the sub-config.json nor sub-testing as this will not be maintainable as the project grows.

How do I exclude only the files/directories located within the CWD?

Asked By: LiamF


This should exclude the first level {prova1,prova3} files in the first level directory and then include the same files in the deeper levels:

rsync -av --include={*/prova1,*/prova3} --exclude={"prova1","prova3"} aa/ bb/
Answered By: user2798699
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.