Wildcards
A wildcard is a sign that stands for many letters in a file name. One wildcard can match many files at once.
The star names many files
Star matches every .txt file in the data folder.
$ cd ~/practice
$ ls data/*.txtThe question mark
The question mark stands for one letter, the l in logs.
$ cd ~/practice
$ echo data/?ogs.txtSquare brackets
The brackets hold l and n, so names that start with either letter match.
$ cd ~/practice
$ echo data/[ln]*.txtCase matters
No file ends in capital TXT, so the pattern stays as typed.
$ cd ~/practice
$ echo *.TXTExample
$ cd ~/practice
$ ls data/*.txt
$ echo *.TXTKey points
- The star matches any characters, even none at all.
- The question mark matches exactly one character.
- Square brackets match one character from the letters inside them.
- A wildcard is a kind of pattern.
- A glob is another name for a wildcard pattern.
- Matching is case-sensitive.
- Uppercase letters and lowercase letters are not the same.
- One short pattern can name many files at once.
In this example, the star names three files in the data folder. Each name ends in .txt. Then the capital pattern matches nothing, so the shell leaves it as typed.
Note
A wildcard that matches nothing stays as typed.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does *.txt match?