Once again somewhat mystified with exclude rules

Martin Pool mbp at samba.org
Fri Apr 12 20:46:01 EST 2002


On 12 Apr 2002, Harry Putnam <reader at newsguy.com> wrote:
> I go thru this every few mnths it seems.  Rsyncs exclude rules are
> very sophisticated but because of that somewhat unfathomable at
> times.

Remember in 2.5.5 you can use -vv to get an explanation of which
include/exclude rule caused a particular file to be handled a
particular way.  (Suggestions to improve this, as always, are
welcome.)

> Simplified:
> I want to exclude directories named no_bak anywhere in the tree
> but only the files under them, not the direcrories themselves.

Example:

/tmp/harry
|-- foo
|   |-- back
|   |   `-- file
|   |-- file
|   `-- no_back
|       |-- file
|       `-- quux
|           `-- file
|-- no_back
|   `-- file
`-- phono_back
    `-- file

6 directories, 6 files

I think the solution is:

mbp/3 harry$ rsync --exclude '**/no_back/*' --exclude 'no_back/*' /tmp/harry/ /tmp/harry2/ -rvv
building file list ... 
expand file_list to 4000 bytes, did move
excluding directory foo/no_back/quux because of pattern **/no_back/*
excluding file foo/no_back/file because of pattern **/no_back/*
excluding file no_back/file because of pattern no_back/*
done
foo/back/file
foo/file
phono_back/file
total: matches=0  tag_hits=0  false_alarms=0 data=87
wrote 374 bytes  read 68 bytes  884.00 bytes/sec
total size is 87  speedup is 0.20

'**/no_back/*' matches "any number of directory components, then a
directory called no_back, then anything else", so it chops off just
after passing through a directory called no_back.  'no_back/*' clears
up the top level one.

As far as I can see you need both because the first must have a slash
to prevent it matching filenames that just end in no_back.

Result is:

/tmp/harry2
|-- foo
|   |-- back
|   |   `-- file
|   |-- file
|   `-- no_back
|-- no_back
`-- phono_back
    `-- file

5 directories, 3 files

--
Martin




More information about the rsync mailing list