Regular expressions

Wildcard characters

Wildcards are used to match filenames. In addition to literal filenames, the shells recognize the following simple regular expressions:

Matches any string of characters, including the null string (nothing). Thus, foo* matches ``foot'', ``football'' and ``foo''.

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''.

NOTE: By convention, ``dot'' files such as .profile are excluded from such listings. In order to display these, it is necessary to use the ls command's -a option.

Matches any single character. Thus, foo?s will match ``foods'' or ``fools'' but not ``footballs''. To match all files with a name comprising four characters type ls ????.

[ ... ]
Matches one of the characters enclosed in brackets. (This is similar to ``?'', but restricted to the specified set of characters.) For example, the pattern [Aa] matches only the letters ``A'' and ``a''. ls [Aa]ardvark will match files called ``aardvark'' and ``Aardvark''. This is a useful construction in the light of the system's case-sensitivity.

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).

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004