How Do I Use Wildcards to Select Files?
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.
Comments - most recent first
(Please feel free to answer questions posted by others!)
Enter a command to copy all files in your home directory beginning with the
letter 'a' to the current directory.
:qw or :wq
lastly, how about this
all files - hidden or not (*)
If you want to do it recursively, it's rm -rf * with the r being recursively. Use this carefully as it will delete anything, system files and folders included. Force means the system will not prompt you.
"rm -f *"
means remove ("rm")
all ("*" wildcard)
non-hidden files ("-f")
what is the answer?
NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.