Globbing is the operation by which wildcard characters,
`*' or `?' for example, are replaced and expanded into all
existing files matching the given pattern. However, tar
often
uses wildcard patterns for matching (or globbing) archive members instead
of actual files in the filesystem. Wildcard patterns are also used for
verifying volume labels of tar
archives. This section has the
purpose of explaining wildcard syntax for tar
.
@FIXME{the next few paragraphs need work.}
A pattern should be written according to shell syntax, using wildcard characters to effect globbing. Most characters in the pattern stand for themselves in the matched string, and case is significant: `a' will match only `a', and not `A'. The character `?' in the pattern matches any single character in the matched string. The character `*' in the pattern matches zero, one, or more single characters in the matched string. The character `\' says to take the following character of the pattern literally; it is useful when one needs to match the `?', `*', `[' or `\' characters, themselves.
The character `[', up to the matching `]', introduces a character class. A character class is a list of acceptable characters for the next single character of the matched string. For example, `[abcde]' would match any of the first five letters of the alphabet. Note that within a character class, all of the "special characters" listed above other than `\' lose their special meaning; for example, `[-\\[*?]]' would match any of the characters, `-', `\', `[', `*', `?', or `]'. (Due to parsing constraints, the characters `-' and `]' must either come first or last in a character class.)
If the first character of the class after the opening `[' is `!' or `^', then the meaning of the class is reversed. Rather than listing character to match, it lists those characters which are forbidden as the next single character of the matched string.
Other characters of the class stand for themselves. The special construction `[a-e]', using an hyphen between two letters, is meant to represent all characters between a and e, inclusive.
@FIXME{need to add a sentence or so here to make this clear for those who don't have dan around.}
Periods (`.') or forward slashes (`/') are not considered special for wildcard matches. However, if a pattern completely matches a directory prefix of a matched string, then it matches the full matched string: excluding a directory also excludes all the files beneath it.
There are some discussions floating in the air and asking for modifications
in the way GNU tar
accomplishes wildcard matches. We perceive
any change of semantics in this area as a delicate thing to impose on
GNU tar
users. On the other hand, the GNU project should be
progressive enough to correct any ill design: compatibility at all price
is not always a good attitude. In conclusion, it is possible
that slight amendments be later brought to the previous description.
Your opinions on the matter are welcome.
Go to the first, previous, next, last section, table of contents.