--include vs. --exclude

John Van Essen vanes002 at umn.edu
Mon Mar 29 01:16:26 GMT 2004

On Fri, 26 Mar 2004, Phil Howard <phil-rsync-2 at ipal.net> wrote:
> So I have on my server a big file tree.  I want to use rsync to download
> only the PDF files, which make up a small portion of that tree.  So I try
> it this way:
>   rsync -aHPvz --include '*.pdf' --exclude '**' user at host:<source> <destination>
> which gives me nothing.

Hi Phil,

Your goal seems to be to create a tree that consists only of *.pdf
files and their necessary directory nodes.  Right?

The closest you can get to that with standard includes/excludes is
with this combination:

  --include '*/'     (process/create all directory nodes)
  --include '*.pdf'  (include all *.pdf files)
  --exclude '*'      (exclude everything else)

The disadvantage is that you will get the entire tree, even the
branches with no pdf files.

rsync 2.6.0 has a new 'files-from' option which will do what you need,
but you have to create the file list yourself (easy enough to do with
the 'find' command).  But you are at a disadvantage in that you are
doing a pull and may not have access to the source.

Here's a possibility.  Do a --dry-run first to determine the names
of the pdf files.  Grep the -v output of rsync for '\.pdf$', store
that list in a file, then do a real run with the files-from option.

I didn't try this - so I haven't verified that this will work.
        John Van Essen  Univ of MN Alumnus  <vanes002 at umn.edu>

More information about the rsync mailing list