Up: wildcards
For the purposes of this section, we call exclusion members all member names obtained while processing --exclude and --exclude-from options, and inclusion members those member names that were given in the command line or read from the file specified with --files-from option.
These two pairs of member lists are used in the following operations: --diff, --extract, --list, --update.
There are no inclusion members in create mode (--create and --append), since in this mode the names obtained from the command line refer to files, not archive members.
By default, inclusion members are compared with archive members literally 1 and exclusion members are treated as globbing patterns. For example:
$ tar tf foo.tar a.c b.c a.txt [remarks] # Member names are used verbatim: $ tar -xf foo.tar -v '[remarks]' [remarks] # Exclude member names are globbed: $ tar -xf foo.tar -v --exclude '*.c' a.txt [remarks]
This behavior can be altered by using the following options:
Thus, to extract files whose names end in ‘.c’, you can use:
$ tar -xf foo.tar -v --wildcards '*.c' a.c b.c
Notice quoting of the pattern to prevent the shell from interpreting it.
The effect of --wildcards option is cancelled by --no-wildcards. This can be used to pass part of the command line arguments verbatim and other part as globbing patterns. For example, the following invocation:
$ tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'
instructs tar to extract from foo.tar all files whose names end in ‘.txt’ and the file named [remarks].
Normally, a pattern matches a name if an initial subsequence of the name's components matches the pattern, where ‘*’, ‘?’, and ‘[...]’ are the usual shell wildcards, ‘\’ escapes wildcards, and wildcards can match ‘/’.
Other than optionally stripping leading ‘/’ from names (see absolute), patterns and names are used as-is. For example, trailing ‘/’ is not trimmed from a user-specified name before deciding whether to exclude it.
However, this matching procedure can be altered by the options listed below. These options accumulate. For example:
--ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
ignores case when excluding ‘makefile’, but not when excluding ‘readme’.
The --recursion and --no-recursion options (see recurse) also affect how member patterns are interpreted. If recursion is in effect, a pattern matches a name if it matches any of the name's parent directories.
The following table summarizes pattern-matching default values:
Members | Default settings
|
---|---|
Inclusion | --no-wildcards --anchored --no-wildcards-match-slash
|
Exclusion | --wildcards --no-anchored --wildcards-match-slash
|