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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think
--includeis used to include a subset of files that are otherwise excluded by--exclude, rather than including only those files.In other words: you have to think about include meaning don’t exclude.
Try instead:
For rsync version 3.0.6 or higher, the order needs to be modified as follows (see comments):
Adding the
-mflag will avoid creating empty directory structures in the destination. Tested in version 3.1.2.So if we only want *.sh files we have to exclude all files
--exclude="*", include all directories--include="*/"and include all *.sh files--include="*.sh".You can find some good examples in the section Include/Exclude Pattern Rules of the man page