0

I want to use rsync to upload files to a server. I'll default to exclude all. Then I'll include the ones I need.

While doing so I realised sometimes I need to exclude a file within a folder but include the other folders.

I want to use a pattern to do so but I'm not sure what the pattern format should be in order to say "I want to include all subfolders except the one named demo"

--include="models/" --include="models/!demo" --exclude="*"

I definetely don't want to be typing every single folder to include within a folder or every folder to exclude from my project.

I would like to exclude all by default. Then include based on pattern so I won't have to be forced to include the whole folder.

Any idea?

AdminBee
  • 22,803
Alvaro
  • 101

1 Answers1

2

As meuh noted in comments, the inclusion and exclusion patterns are tested in the order they are given on the command line.

To exclude models/demo, but include all other files in that directory, and exclude everything else, use

--exclude=models/demo --include='models/***' --exclude='*'

The models/*** pattern matches the models directory as well as everything beneath it. The models/demo directory or file will be excluded as that exclusion pattern is specified first.

Kusalananda
  • 333,661
  • Thanks for highlighting this. I hadn't been able to find this information, which is explained further near the bottom of the rsync manpage. It's rather frustrating that this is so different from how e.g. gitignore patterns or shell globs work, but at least we actually have decent documentation. – Steven Lu Jan 23 '21 at 08:21