include exclude help please.

Dave Dykstra dwd at bell-labs.com
Fri Mar 22 03:17:46 EST 2002


On Tue, Mar 19, 2002 at 11:55:50AM -0800, Wayne Davison wrote:
> Seems to me that the simplest solution is to name the directory
> explicitly:
> 
> rsync -a --include "*/" --include "*.tif" --exclude "*" /film/jonah /tmp/film
> 
> To accomplish the same thing using includes, you could do this:
> 
> rsync -a --include /jonah --include "/jonah/**/" --include "*.tif" \
>          --exclude "*" /film/ /tmp/film
> 
> If you want to exclude any empty directories that either of these
> commands creates, you'll have to be more specific in the directory path
> that is allowed to succeed.  I.e., if there's a "foo/bar" path inbetween
> jonah and sourceimages, you'd need to do something like this:
> 
> rsync -a --include /jonah --include /jonah/foo --include /jonah/foo/bar \
>          --include /jonah/foo/bar/sourceimages --include "*.tif" \
> 	 --exclude "*" /film/ /tmp/film
> 
> I haven't tested any of these, but they look right to me.
> 
> ..wayne..


Let me explain Wayne's answer a little further.  The main thing you need to
understand is that the exclude algorithm is applied recursively so any time
there's an exclude that matches a directory, rsync will not descend any
further so if you're using --exclude '*' you need to include all
directories above what you want to copy.  Also, the basename of the source
directory is included in the patterns if the source directory doesn't end
with a slash.  This would be the straightforward answer:

    rsync -avv --include "/film/" --include "/film/jonah/" \
	--include "/film/jonah/**/" --include "/film/jonah/**/sourceimages/ \
	--include "/film/jonah/**/sourceimages/*.tif" --exclude "*" /film /tmp

Wayne observed though that the pattern ending with **/ is going to include
all directories under /film/jonah/, so (a) you don't need to explicitly
include the sourceimages directory and (b) it's likely to still include a
lot more directories that you don't want.  Can you live with his suggestion
to explicitly list all directories in between?


On Wed, Mar 20, 2002 at 11:03:09AM -0600, Joe Rice wrote:
> tim.conway at philips.com(tim.conway at philips.com)@Tue, Mar 19, 2002 at 12:53:44PM -0700:
...
> > I think that if i were you, I'd use
> > rsync -a --include='*.tif' --exclude '*' --relative `find /film/jonah 
> > -type d -name sourceimages -print` /tmp
...
> The --relative 'find ' trick didn't work, but i still have to play
> with it some to see if i can get it to work.

Ah, this is probably the best way to go, but you need a trailing slash on
the end of each of the directories or else the "sourceimages" is going to
get excluded by the --exclude '*'.  Try piping the find through
    sed 's,$,/,'


I too can't wait to see "Jonah".  My kids have seen all the Veggie Tales
and 3-2-1 Penguin videos.  Also, I live in the Chicago area and have run
into a guy in my hometown's new library a couple times who told me he works
on Penguin 3.  I'm delighted to know that rsync is helping Big Idea.

- Dave Dykstra




More information about the rsync mailing list