using rsync include exclude patterns matches whitespace

203 Views Asked by At

i've encountering problems when I use rsync (v3.2.3 on a Pi with Raspbian) with directories containing a whitespace at the end. example:

pi:~ $ find source/
source/
source/hello
source/hello/whitespace_dir  <--- dir with whitespace at the end
source/hello/whitespace_file <--- file with whitespace at the end
source/foo
source/foo/bar1
source/foo/bar2

output of a dry run rsync:

pi:~ $ rsync -aHv --dry-run --include="*/" --include="bar" --exclude="*" source/ target/
sending incremental file list
./
foo/
foo/bar1/
foo/bar2/
hello/
hello/whitespace_dir /

The -vvv explanation says

[sender] hiding file hello/whitespace_file  because of pattern *
[sender] pushing local filters for /home/pi/source/hello/whitespace_dir /

Why? I just want to copy all dir's AND files matching the pattern "bar".

1

There are 1 best solutions below

0
On

Using

rsync -rmv --dry-run --include="*/" --include="*/*bar*" --exclude="*" source/ target/

will give you what you want.

rsync will not report files unless your include regex pattern covers the conditions to match the desired files.

Note rsync logic to pass information for all levels of parent directories to reach the identified files, not just the fullpath of the files themselves.