Reputation: 30980
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
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
Reputation: 1011
I fixed the problem changing --exclude=* by --exclude=*.*, I understand that * exclude folder where include files are.
Upvotes: 8
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
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