user881480 user881480 - 1 year ago 92
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

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download