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
  • 21,637
  • 21
  • 47
  • 71
Alvaro
  • 101
  • 3
  • Nope. I saw it before. – Alvaro Apr 17 '20 at 17:06
  • Rather than saying "No", please explain why it doesn't help. Your requirement seems to fit the proposed duplicate very well. – roaima Apr 17 '20 at 17:25
  • i didn't see anywhere where I can specify " i want to include all subfolders except the one named demo" – Alvaro Apr 17 '20 at 17:36
  • 3
    The patterns are tested in the order you give them, so you can try --exclude=models/demo --include='models/*' – meuh Apr 17 '20 at 18:39

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
  • 320,670
  • 36
  • 633
  • 936
  • 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