user881480 user881480 - 7 months ago 23
Bash Question

rsync copy over only certain types of files using include option

I use the following bash script to copy only files of certain extension(in this case *.sh), however it still copies over all the files. what's wrong?


from=$1
to=$2

rsync -zarv --include="*.sh" $from $to

Answer

I think --include is used to include a subset of files that are otherwise excluded by --exclude, rather than including only those files.

Try instead:

rsync -zarv  --include "*/" --exclude="*" --include="*.sh" "$from" "$to"

UPDATE:

For rsync version higher than 3.0.7, the order needs to be modified as follows (see comments)

rsync -zarv --include="*/" --include="*.sh" --exclude="*" "$from" "$to"
Comments