rsync --include option does not exclude other files rsync --include option does not exclude other files bash bash

rsync --include option does not exclude other files


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/


--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/xxxrsync -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)


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.