Hi there, is it possible to use regular expressions in the exclude-paramter of rsync ? For example: rsync --exclude "/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr]" I've tried it, but it will take no effect. -- SET THE CONTROLS FOR THE HEART OF THE SUN Jens
I was waiting for someone more knowledgeable to respond, as the specific example you gave is covered and approved in the documentation, but i saw the "test" message sent less than 6 hours later, so I figure you must be under the gun. From the man page: o if the pattern contains a wildcard character from the set *?[ then expression matching is applied using the shell filename matching rules. Otherwise a simple string match is used. Your pattern fits this description, so it looks like you might have found a bug. rsync does not support regular expressions, but rather a simplified set of matching rules. There has been some talk about adding regex, but that's a big project. What you show, though, is not a regular expression, but a shell pattern, which should work with rsync if you fix the syntax: --exclude=PATTERN exclude files matching PATTERN SunOS 5.7 Last change: 25 Jan 2002 6 User Commands rsync(1) Change rsync --exclude "/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr]" to rsync --exclude=/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr] and try again. Frankly, I'm surprised you didn't get a usage message from that one. Note that I removed the quotes. They are not necessary, since you won't get any shell globbing of your pattern, because of the pattern being connected to "--exclude" by "=". The quotes won't break anything, so you can leave them in. Tim Conway tim.conway@philips.com 303.682.4917 office, 3039210301 cell Philips Semiconductor - Longmont TC 1880 Industrial Circle, Suite D Longmont, CO 80501 Available via SameTime Connect within Philips, n9hmg on AIM perl -e 'print pack(nnnnnnnnnnnn, 19061,29556,8289,28271,29800,25970,8304,25970,27680,26721,25451,25970), ".\n" ' "There are some who call me.... Tim?" "J.Strohschnitter" <svebu@gmx.de> Sent by: rsync-admin@lists.samba.org 06/24/2002 02:30 AM To: rsync@lists.samba.org cc: (bcc: Tim Conway/LMT/SC/PHILIPS) Subject: RegExpr in ---exclude Classification: Hi there, is it possible to use regular expressions in the exclude-paramter of rsync ? For example: rsync --exclude "/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr]" I've tried it, but it will take no effect. -- SET THE CONTROLS FOR THE HEART OF THE SUN Jens -- To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Sorry. I didn't mean to imply that the "=" is anything special, just that it shrinks the possible shell globs to the list to matching items in the "--exclude=" subdirectory. If that globs, you're using wierd filenames.... Not that that can't happen: tconway@alta:/users/tconway/test>find . -print. ./--exclude./--exclude=/path ./--exclude=/path/to ./--exclude=/path/to/a ./--exclude=/path/to/a/FoLdEr tconway@alta:/users/tconway/test>But the, that would be awfully inconvenient, wouldn't it. tconway@alta:/users/tconway/test>rm -rf *rm: unrecognized option `--exclude=' Try `rm --help' for more information. tconway@alta:/users/tconway/test>rm -rf --excluderm: unrecognized option `--exclude='Try `rm --help' for more information. tconway@alta:/users/tconway/test>Nonetheless, If you don't consider what will happen to your tape drive if someone uses it for a sandwich warmer, your first support call is sure to be on that topic. Cheers, Tim Conway tim.conway@philips.com 303.682.4917 office, 3039210301 cell Philips Semiconductor - Longmont TC 1880 Industrial Circle, Suite D Longmont, CO 80501 Available via SameTime Connect within Philips, n9hmg on AIM perl -e 'print pack(nnnnnnnnnnnn, 19061,29556,8289,28271,29800,25970,8304,25970,27680,26721,25451,25970), ".\n" ' "There are some who call me.... Tim?" "Bernard A Badger" <bab@vx.com> Sent by: rsync-admin@lists.samba.org 06/24/2002 12:05 PM To: <rsync@lists.samba.org> cc: (bcc: Tim Conway/LMT/SC/PHILIPS) Subject: RE: RegExpr in ---exclude Classification: Just a comment on shell glob usage---see below.> -----Original Message----- > From: rsync-admin@lists.samba.org [mailto:rsync-admin@lists.samba.org]On > Behalf Of tim.conway@philips.com > Sent: Monday, June 24, 2002 12:29 PM > To: J.Strohschnitter > Cc: rsync@lists.samba.org > Subject: Re: RegExpr in ---exclude >[SNIP]> User Commands rsync(1) > > Change > rsync --exclude "/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr]" > to > rsync --exclude=/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr] > and try again. Frankly, I'm surprised you didn't get a usage messagefrom> that one. > > Note that I removed the quotes. They are not necessary, since you won't > get any shell globbing of your pattern, because of the pattern being > connected to "--exclude" by "=". The quotes won't break anything, soyou> can leave them in.Well, sort of. The "=" isn't special, is just because it's all one "word". Shell globbing is done before the program is invoked, so the shell globs on "--exclude=/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr]", but unless you have a directory "--exclude=", it won't find anything. It _does_ look for it, though, so it might be kinda slow in a populous directory. It's not strictly necessary, but I don't like to advise other people to do something that "mostly" works, without making the risks clear. If you know that no such directory exists, use it. Just don't forget that you're using a loophole. Isn't there some option in some shell that causes commands to fail if a glob doesn't generate a result? If you didn't remember to enter the quotes, you could go ahead because you know what you're doing. Command syntax with globs are inherently risky, beware of files named "-?" like "-r", "-f" and "-q". That's why the "--" option was invented, to keep the glob away from the options. Be extra careful when you are writing shell scripts. They'll be invoked in ways you never imagined, so write defensively. -- To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html
On Mon, 24 Jun 2002, J.Strohschnitter wrote:> is it possible to use regular expressions in the exclude-paramter of rsync ? > For example: > > rsync --exclude "/path/to/*/[Ff][Oo][Ll][Dd][Ee][Rr]"That's still a valid match pattern (and a poor regular expression -- "/*" would match zero or more slashes as a regex, so that would have to turn into "/.*"). What you're trying to specify is probably failing due to one or more of these problem areas: - You have to use "**" to match any depth of subdirs in between the path and the name parts. I.e. "/path/to/**/[Ff][Oo][Ll][Dd][Ee][Rr]". - Excludes anchor starting at the root of the transfer, not the root of the file system. In other words, if you're sending "/path/*", you'd have to leave off the "/path" in the exclusion. - You might want to leave off the path altogether. Using just the name "[Ff][Oo][Ll][Dd][Ee][Rr]" would exclude that name at any point in the tree. This is like specifying "**/[Ff][Oo][Ll][Dd][Ee][Rr]", but it also matches in the root dir of the transfer, and is more efficient. ..wayne..