0

I'm trying to sync files with pattern */ls from folder /bin to folder test:

mkdir test
rsync -avv --exclude='*' --include=*/ls /bin/ test/
ls test

And from the output the include filter failed to work:

[sender] hiding file ls because of pattern *

Anyone know what's wrong?

1
  • The wildcard excludes everything, it is as simple as that. (And takes precedence over inclusion).
    – Paradox
    Feb 22, 2022 at 12:05

1 Answer 1

2

The exclusion and inclusion filters are evaluated from left to right. In your command line, this means that everything is excluded. The inclusion filter is not having any effect, as the exclusion pattern has already matched every conceivable name.

Instead, to copy every file called ls from /bin or any of its sub-directories, use

rsync -av -m --include='*/' --include='ls' --exclude='*' /bin/ test/

Put the inclusion patterns first and exclude everything not explicitly included last. You will need to match */ with an inclusion pattern as you may want to descend into subdirectories (at least in the general case). I've also added -m, which avoids creating directories on the destination if there are no files in them.

If you don't need recursion and want /bin/ls copied with rsync, then use

rsync -av /bin/ls test/

The slash at the end of the destination pathname in the two commands shown here is unnecessary but will force the command to fail if test is not a directory. It acts as an assertion, in a way.

You must log in to answer this question.

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