Using Wildcards to Select Multiple Files in Linux
Often, a directory contains lots of files that have similar filenames. Sean’s digital camera, for example, creates files with names like these:
If you want to delete a group of them, or to copy them or do anything else with them, you don’t want to repeat the command typing out each file name in turn. Computers are good at repetition, so it’s better to leave the donkey work to the shell.
Wildcards enable you to do that. Instead of giving a specific filename to a command, you can give it a pattern to match, such as all the files that begin with img, or all the files that have the extension .jpg. The asterisk wildcard replaces any number of any character, so *.jpg returns any filenames that end with .jpg, no matter how long they are, and no matter how many of them there are. The question mark asterisk replaces just one character, so img?.jpg would select img1.jpg, img2.jpg, and imgb.jpg, but ignore img11.jpg or any other longer filenames.
If you want to choose files that begin with a particular letter, you can use the square brackets wildcard. To choose any files beginning with the letters a, b, or c, you would use [abc]*. To narrow that down to just those that end with .jpg, you would use [abc]*.jpg.
Table 5-3 provides a quick reference to the wildcards you can use, with some examples.
You can use wildcards anywhere you would usually use a filename. For example, you ...