Wildcards in File Names Directories


Wildcards in File Names & Directories

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.

Tip

  • The brackets wildcard can include individual characters, such as [ABCD] or character ranges, such as [A-G] or [1-6].


Using wildcards

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.

Figure 18. These examples show how you can use the asterisk wildcard to list specific files in a directory.


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

Figure 19. These examples show the question mark wildcard in action. (Both dir1 and dir2 are empty directories; that's why no files are listed for them.)


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

Figure 20. Here are two examples for the bracket wildcard.


To view a directory list using a wildcard

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 (Figures 18, 19, and 20).



Visual QuickStart Guide. Mac OS X 10. 4 Tiger
Mac Os X 10.4 Tiger (Visual Quickstart Guides)
ISBN: 0321423372
EAN: 2147483647
Year: 2003
Pages: 301
Authors: Maria Langer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net