I am using rsync with the include-from="external file" option. Apart from that my problem is almost identical to this one.

I want to backup a very specific subfolder, while generally not backup any hidden folders. The only way I managed to do this is painstakingly this way:

+ home/*/.config/libreoffice/
+ home/*/.config/libreoffice/4/
+ home/*/.config/libreoffice/4/user/
+ home/*/.config/libreoffice/4/user/registrymodifications.xcu

# hide the rest ( .local, .wine, most of .config ...)
- home/*/.*/

Without the 3 initial lines, registrymodifications.xcu will be excluded, because its higher-level directories are unmatched until they are “hit” by the very last line... so by my experience I must whitelist them all, piece by piece.

Is there a less painful way to do this? (I'd still want to keep all my backup rules in a single, external file...)

1 Answer 1


On the command line, I would do this like so:

rsync -ai \
    --prune-empty-dirs \
    --include='*/' \
    --exclude='*' \
    "$source" "$destination"

This includes all directories, the registrymodifications.xcu subdirectory and all files beneath it, recursively, but then excludes everything not explicitly included by other rules. It also uses --prune-empty-dirs (-m), which means that empty directories will not be created on the destination.

The effect is that only the files and directories matching the second inclusion rule would actually be transferred.

Or, as a filter file:

+ */
+ home/*/.config/libreoffice/4/user/registrymodifications.xcu/***
- *

... which you would use as

rsync -ai \
    --prune-empty-dirs \
    --include-from=patterns \
    "$source" "$destination"

A caveat for this is that empty directories matching the second inclusion rule would not be created on the destination, due to the --prune-empty-dirs option.

  • after - * I would need to (finally) add my standard chores (like /home/*, /depot/* and so on...), but smart solutions with the “directories lever” and then limiting the damage with --prune-empty-dirs 👍
    – Frank N
    Commented Feb 1, 2022 at 11:54
  • 1
    @FrankNocke - * would hide everything not already selected for inclusion or exclusion, so there's no need to hide /home/* etc. separately. You can add more rules if you wish, but they would have no effect.
    – Kusalananda
    Commented Feb 1, 2022 at 11:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .