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
Popular Linux Topics
Linux IntroLinux Tutorial
Who is Doctor Bob?Linux Basics
Living in a ShellLinux Files
The Linux File SystemLinux Commands
Important Linux CommandsLinux Editors
The Vi EditorLinux Data Manipulation
Slicing & DicingLinux Shell Programming
Linux Shell ScriptsPerl Programming
Perl BasicsLinux and Email
Sending EmailCompression and Encoding
Linux File CompressionLinux Does DOS
Accesing DOS FilesManaging Linux
Updating Your Linux System