I'm trying to copy the yaml files in my project to a dist folder, preserving the structure. However it is copying node_modules which I don't want. How do I exclude with rsync and why does my below command not work?

rsync -R --exclude=node_modules ./**/**.yaml dist

Note I've tried the variants, etc:

rsync -R --exclude= node_modules ./**/**.yaml dist
rsync -R --exclude 'node_modules' ./**/**.yaml dist

my folder structure:


and I want the above to show up in my dist as:


I have managed to get this working as follow:

$ rsync -r --exclude="node_modules" projectroot/* dist/

I ended up going with:

rsync -avrmR --exclude='node_modules/' --include='*/' --include='*.yaml' --exclude='*' ./ ./dist

How it works is it first excludes anything in the node_modules folder, then includes all directories and then includes only yaml files and then excludes everything else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.