user881480 user881480 - 8 months ago 29
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?


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


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"


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"