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/
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/
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/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)
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.
I fixed the problem changing --exclude=* by --exclude=*.*, I understand that * exclude folder where include files are.