trying to understand --include and --exclude

Phil Howard phil-rsync-2 at
Fri Dec 2 23:17:06 GMT 2005

On Sun, Nov 27, 2005 at 05:13:30PM -0500, Aaron Morris wrote:

| I think you are trying to include too many things in a single
| include/exclude statement.  You need to break everything down to
| files, folders, and sets of files in a single folder.  For example, if
| you want to transfer a file 3 directories deep, each parent directory
| needs to be included if there is a global exclude at the end of your
| statements.

What if I want to include a particular pattern of files in which its
parent directory is a given directory, but this combination can be
found at various levels, such as:


I would think the "**" pattern would cover multiple levels, so the
pattern "**/2005/07.tar.bz2" should cover that.  But the issue is
what about the directories?

I think the problem here is that I have to also match every possible
parent directory as each is individually applied to all the patterns,
else the directory won't be created.  The better solution it seems to
me would be to have a general option like:  --create-parent-directories
which would basically have the semantic meaning that for anything that
does match, create the directories necessary for it, much like the -p
option on mkdir.

| The following will probably give you what you want:
| --include "/*"  (include all files at root of transfer)
| --include "/*/2005/" --include "/*/2005/07.tar.bz2" (include file
| 07.tar.bz2, you must also include the folder that contains the file
| because of the next statement)
| --exclude "*"  (exclude everything not explicitly included)
| I haven't tested it, so YMMV.

I ended up getting it working with this combination:

--include "*/2005"
--include "*/2005/07.tar.bz2"
--exclude "*/*"
--include "*"
--exclude "*/**"

(in reality a much larger list to handle a lot more stuff really being done)

I don't recall if what you suggested was tried or not.  I went through so
many combinations.  One problem is, there are no messages to explain why
some file is, or is not, matched, so it is very hard to figure this out.
I suspect I still don't really grasp the whole picture of how this works.
It's certainly not the way I would have designed it.

| Phil Howard KA9WGN       | |
| (first name) at | |

More information about the rsync mailing list