There are lots of files in /dapp/parsD/parsapp/object. I only want to rsync the files in this directory that match *.sql, *.pl and *.sh, but I also want to exclude 2 specific patterns in the same directory that end in .sh.

Is this possible? I am running HP-UX 11i on both source and destination. rsync version is 3.1.0.

The below may be easier to visualize. On the dev server, the 'x' or 'X' is replaced by 'd' or 'D', and on production server, it will be 'p' or 'P'.

Include the following files:


But exclude the following files:


1 Answer 1


rsync include/exclude/filter rules can be a pain to work with, but are ultimately very flexible. Here is one way to do what you want:

rsync --include-from=- /xapp/parsX/parsapp/object/ dest_dir <<EOF
- getbackdate*autosys.sh
- parssendevent*.sh
+ *.sql
+ *.pl
+ *.sh
- *

The --include-from makes rsync read the patterns from stdin, without this you could specify each pattern as a separate --include or --exclude option. You can also put the rules in a file and specify the name or use -F to make rsync look for a .rsync-filter file in each directory it reads.

Note also that the order of the patterns is also significant. Files are included/excluded according to the first pattern that matches them. Also, the - * rule at the end is necessary to make include rules work since everything is included by default. However this can be problematic with recursive transfers since it excludes all directories not explicitly included. One way around this is to include a + **/ rule to include all directories.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .