|
|
Wildcards are used to match filenames. In addition to literal filenames, the shells recognize the following simple regular expressions:
For example,
ls
will match all the files in the current directory and its
subdirectories.
(The shell expands the ``
'' pattern; the ls
command displays the results.)
ls g will match all files beginning with the letter
``g''. In this case, the shell interprets the regular
expression as meaning ``any string of zero or more characters
following a letter ``g''.
A pair of characters separated by a ``-'' is taken to be a
locale-dependent range.
For example, [A-Z] in the C locale is equivalent to
[ABCDEFGHIJKLMNOPQRSTUVWXYZ] and
ls [a-m] will match all the files beginning with the
letters ``a'' to ``m''.
If the first character after the
opening bracket is an exclamation mark (!), then any
character not enclosed in the brackets is matched. For
example, [!0-9] will match any character except a digit.
ls [!a-m]
will match all the files that do not begin with letters ``a''
through ``m''.
Because the hyphen has a special meaning in a set, you can match
a literal hyphen within a set only by placing it at the beginning
or the end of the set. For example,
ls [abcde-]
will match files beginning with a--e or -.
The characters represented by a range using the hyphen will vary depending on the current locale. For example, in a non-C locale [A-Z] represents the characters AbBCc....YyZ, rather than only all capital letters as in the C locale.
For more information about wildcard regular expressions, see regexp(1tcl).