start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

28.3. Use Wildcards to Create Files?

The shells' [ ] (square bracket) wildcards will match a range of files. For instance, if you have files named afile, bfile, cfile, and dfile, you can print the first three by typing:

% lpr [a-c]file

Now, let's say that you want to create some more files called efile, ffile, gfile, and hfile. What's wrong with typing the command line below? Try it. Instead of vi, you can use your favorite editor or the touch (Section 14.8) command:

% vi [e-h]file   Doesn't make those four files
% ls
afile   bfile   cfile   dfile

Stumped? Take a look at Section 1.13 about wildcard matching.

The answer: wildcards can't match names that don't exist yet. That's especially true with a command like touch ?file (Section 14.8) or touch *file -- think how many filenames those wildcards could possibly create!

Section 28.4 explains shell { } operators that solve this problem. And, by the way, if you just created one new file named [e-h]file, simply quote (Section 27.12) its name to remove it:

rm "[e-h]file"

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.