Chapter 16
Wildcard Matching
16.1 Do This
Source 29: Linux/Mac OSX Exercise
16
$ cd temp $ ls *.txt ex12.txt ex13.txt ex14.txt uncool.txt
$ ls ex*.* ex12.txt ex13.txt ex14.txt
$ ls e* ex12.txt ex13.txt ex14.txt $ ls *t
ex12.txt ex13.txt ex14.txt uncool.txt
$ cat *.txt > bigfile.txt $ rm *.txt $ ls $
Source 30: Windows Exercise
16
> cd temp > ls *.txt Directory: C:\Users\zed\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12/22/2011 5:23 PM 38 another.txt
-a--- 12/22/2011 5:23 PM 38 ex15.txt > ls ex*.*
Directory: C:\Users\zed\temp Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12/22/2011 5:23 PM 38 ex15.txt > ls e*
Directory: C:\Users\zed\temp Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12/22/2011 5:23 PM 38 ex15.txt > ls *t
Directory: C:\Users\zed\temp Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12/22/2011 5:23 PM 38 another.txt
-a--- 12/22/2011 5:23 PM 38 ex15.txt
> cat *.txt I am a new file. I am a new file. > rm *.txt > ls >
16.2 You Learned This
Sometimes you want to do a command to a set of files all at once. The way you do
this is to use the * (asterisk) symbol to say "anything." Wherever you put the
asterisk, the shell will build a list of all the files that match the non-asterisk
part.
In this exercise you list out various files that you've made so far. I have
a few extra that were hanging out in my directory, and you might have
others. The key is that, by writing *.txt, you are saying "anything ending in
.txt".
At the end we use rm *.txt to remove all of the .txt files in the temp directory.
16.3 Do More
- Add the * to your deck of flash cards. On the back write: "matches
anything in a wildcard like *.txt".