user121196
user121196

Reputation: 30980

rsync --include option does not exclude other files

trying to rsync files of certain extension(*.sh), but the bash script below still transfer all the files, why?

from=/home/xxx
rsync -zvr --include="*.sh" $from/*  root@$host:/home/tmp/

Upvotes: 31

Views: 32845

Answers (4)

that other guy
that other guy

Reputation: 123400

--include is for which files you want to not --exclude. Since you haven't excluded any in future arguments, there's no effect. You can do:

from=/home/xxx
rsync -zvr --include="*.sh" --include="*/" --exclude="*" "$from" root@$host:/home/tmp/

To recursively copy all .sh files (the extra --include to not skip directories that could contain .sh files)

Upvotes: 24

estevo
estevo

Reputation: 1011

I fixed the problem changing --exclude=* by --exclude=*.*, I understand that * exclude folder where include files are.

Upvotes: 8

lbutlr
lbutlr

Reputation: 424

On thing to add, at least on my machines (FreeBSD and OS X), this does not work:

rsync -aP --include=*/ --include=*.txt --exclude=* * /path/to/dest

but this does:

rsync -aP --include=*/ --include=*.txt --exclude=* . /path/to/dest

Yes, wildcarding the current directory seem to override the exclude.

Upvotes: 7

JohnQ
JohnQ

Reputation: 714

You need to add a --exclude all and it has to come after the --include

rsync -zvr --include="*.sh" --exclude="*" $from/*  root@$host:/home/tmp/

Upvotes: 28

Related Questions