|
|
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''.
(Note that 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.)
A pair of characters separated by a ``-'' is taken to be a range. For example, [A-Z] 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 -.