One frustrating activity in Mac OS 9.x and earlier was working with a group of files. Other than Shift-clicking or dragging to select the group, you had no good way to select group items by namefor example, to select all files that started with the characters
file and ended with the characters
.doc .
Unix, however, makes this easy by enabling you to use three special characters as wildcards:
Asterisk (*), which is referred to as star, is a wildcard for zero or more charactersany character!
Question mark (?) is a wildcard for any single character.
Brackets ([ and ]) around one or more characters act as a wildcard for any of the enclosed characters.
You can place the wildcard wherever you want in the name you are searching for. As you can imagine, wildcards are powerful tools for selecting or listing files or subdirectories.
The brackets wildcard can include individual characters, such as [ABCD] or character ranges, such as [A-G] or [1-6].
The best way to explain how you can use wildcards is to show you some examples.
Suppose your Documents subdirectory contained the following subdirectories and files:
dir1 | file03.doc | file12.txt |
dir2 | file04.doc | file20.txt |
dir30 | file05.doc | file21.txt |
file01.doc | file10.txt | file38.txt |
file02.doc | file11.txt | file39.txt |
Here are some examples to illustrate the asterisk wildcard (Figure 18 ):
To work with all the files that start with the characters
file , you enter file*.
To work with all the files that begin with the characters
file and end with the characters
doc , you enter file*doc.
To work with all the files that end with the characters
txt , you enter *txt.
These examples illustrate the question mark wildcard (Figure 19 ):
To work with files named
file10.txt, file11.txt , and
file12.txt , you enter file1?.txt.
To work with files named
file10.txt and
file20.txt , you enter file?0.txt.
To work with subdirectories named
dir1 and
dir2 , you enter dir?.
To work with files named
file01.doc, file11.txt , and
file21.txt , you enter file?1.*. (Okay, so that one uses two wildcards.)
And these examples illustrate the brackets wildcard in action (Figure 20 ):
To work with files named
file11.txt and
file12.txt (but not
file10.txt ), you enter file1[12].txt.
To work with files named
file01.doc, file10.txt , and
file11.txt , you enter file[01][01].*. (Yes, that's another one with multiple wildcard characters.)
Type ls followed by the search string for the files or directories you want to display (see previous examples) and press
A list containing only the files and directories that match the search string appear (