Doctor Bob
Linux Topic
Search

 
TOURBUS
HOME PAGE
SAVVY
CONSUMER
FREE TECH
SUPPORT

LINUX FILES

How Do I Use Wildcards to Select Files?

Using Wildcards

Wildcards come in quite handy when you want to operate on more than one file at a time. You can use wildcards with any of the commands in this section to list, copy, rename, or delete groups of files or directories.
The asterisk (*) character will match any number of characters in a file name, so consider these examples in light of the animals directory we used earlier.

$ ls -l c*
-rw-r--r-- 1 hermie users 45090 Mar 23 23:17 cat_info
-rw-r--r-- 1 hermie users 64183 Feb 14 22:07 cow_info
$ mv *inf* ../docs
$ rm -f *

The first command lists only those files that begin with the letter "c." The second will move files with the term inf anywhere in the name to another directory. The third command will delete all (nonhidden) files from the current directory.

Note: The expansion of the wildcard is done by the shell, not the command you are running. This means that when you enter the command

rm -f *

the shell expands the wildcard by replacing it with all files that match and actually ends up executing this command:

rm -f cat_info cow_info dog_info pig_info slugs zippity

This might seem a bit arcane, but it's actually important. Since the shell handles the wildcards in Linux, you don't have to worry about which commands accept wildcards and which don't. This is quite different from DOS, where only certain commands work with wildcards.

Here's a little pop quiz: What will be left in the animals directory if you execute the rm command in the preceding example? Try it and then use the ls -al command--you may be surprised at the answer.

Previous Lesson: Deleting Files and Directories
Next Lesson: The Nine Deadly Keystrokes

[ RETURN TO INDEX ]




Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Help>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.