This article summarizes the wildcards that are used for filename expansion (see Table 33-1). The shells use the same basic wildcards, though most shells have some extensions. Unless otherwise noted, assume that wildcards are valid for all shells.
Table 33-1. Filename wildcards
Wildcard |
Shells |
Description |
---|---|---|
|
All |
Match zero or more characters. For example, |
|
All |
Match exactly one
character. For example, |
|
All |
Match
any character listed in the brackets. For example, |
|
All |
Match all characters between a and z, in a case-sensitive
manner, based on the characters' value in the ASCII
character set. For example, |
|
bash, ksh, zsh, newer sh |
Match any
character that does not appear within
the brackets. For example, |
tcsh, zsh |
Match any character that does not
appear within the brackets. For example, | |
|
zsh |
Any number in the range |
|
bash, csh, pdksh, zsh |
Match
word1, word2,
etc. For example, |
ksh, bash2 |
Match zero or one instance of any of the specified
patterns. For example, | |
ksh, bash2 |
Match zero or more instances of any of the specified
patterns. For example, | |
ksh, bash2 |
Match one or more instances of any of the specified
patterns. For example, | |
ksh, bash2 |
Match exactly one of any of the specified patterns. For
example, | |
ksh, bash2 |
Match anything that doesn't contain any of the specified
patterns. For example, | |
|
tcsh, zsh |
Match any name that
doesn't match |
|
zsh |
Match either
|
|
zsh | |
|
zsh |
Search recursively, following symbolic links to directories. |
|
zsh |
Matches zero or
more occurrences of the pattern |
|
zsh |
Matches one or more occurrences of the pattern
|
Note that wildcards do
not match files whose names begin with a dot (.), like .cshrc. This prevents you from deleting (or otherwise mucking
around with) these files by accident. The usual way to match those files is to
type the dot literally. For example, .[a-z]*
matches anything whose name starts with a dot and a lowercase letter. Watch out
for plain .*
, though; it matches the
directory entries .
and ..
. If you're constantly needing to match
dot-files, though, you can set the bash
variable glob_dot_filenames and the zsh option GLOB_DOTS to
include dot-files' names in those shells' wildcard expansion.
You can prevent wildcard expansion by quoting ( Section 27.12, Section 27.13), of course. In the C shells, you can stop all wildcard expansion (which is also called globbing, by the way) without quoting if you set the noglob shell variable. In bash, ksh, and zsh, set the noglob option.
And a final note: many
operating systems (VAX/VMS and DOS included)
consider a file's name and extension
to be different entities; therefore, you can't use a single wildcard to match
both. What do we mean? Consider the file abc.def. Under DOS
or VMS, to match this filename you'd need the wildcard expression *.*
. The first *
matches the name (the part before the period), and the second
matches the extension (the part after the period). Although Unix uses
extensions, they aren't considered a separate part of the filename, so a single
*
will match the entire name.
—JP, ML, and SJC