[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Controlling Pattern-Matching

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 (19) and exclusion members are treated as globbing patterns. For example:

$ tar tf foo.tar
# Member names are used verbatim:
$ tar -xf foo.tar -v '[remarks]'
# Exclude member names are globbed:
$ tar -xf foo.tar -v --exclude '*.c'

This behavior can be altered by using the following options:


Treat all member names as wildcards.


Treat all member names as literal strings.

Thus, to extract files whose names end in ‘.c’, you can use:

$ tar -xf foo.tar -v --wildcards '*.c'

Notice quoting of the pattern to prevent the shell from interpreting it.

The effect of ‘--wildcards’ option is canceled 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 section Absolute File Names), 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’.


If anchored, a pattern must match an initial subsequence of the name’s components. Otherwise, the pattern can match any subsequence. Default is ‘--no-anchored’ for exclusion members and ‘--anchored’ inclusion members.


When ignoring case, upper-case patterns match lower-case names and vice versa. When not ignoring case (the default), matching is case-sensitive.


When wildcards match slash (the default for exclusion members), a wildcard like ‘*’ in the pattern can match a ‘/’ in the name. Otherwise, ‘/’ is matched only by ‘/’.

The ‘--recursion’ and ‘--no-recursion’ options (see section Descending into Directories) 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:

MembersDefault settings
Inclusion--no-wildcards --anchored --no-wildcards-match-slash
Exclusion--wildcards --no-anchored --wildcards-match-slash

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on August 23, 2023 using texi2html 5.0.