Wildcards
Many files at once.
Imagine your downloads folder has fifty photos, and you want to move them all. Typing fifty names would take forever. Wildcards let you describe many files with one short pattern.

- Fifty photos to move
- Typing every name? No
- One pattern for many files
The star
Here's a messy downloads folder. The star matches any characters, any number of them. So star dot JPG means, every name that ends in dot JPG. And invoice star means every name that starts with invoice.
ls invoice-feb.pdf notes1.txt notes2.txt photo2.jpg setup.deb invoice-jan.pdf notes10.txt photo1.jpg photo3.jpg song.mp3 ls *.jpg photo1.jpg photo2.jpg photo3.jpg ls invoice* invoice-feb.pdf invoice-jan.pdf
The question mark
A question mark matches exactly one character. Notes question mark dot TXT matches notes one, and notes two, but not notes ten, because ten has two characters there. Square brackets match one character from a list, like photo, one or three.
ls notes?.txt notes1.txt notes2.txt ls photo[13].jpg photo1.jpg photo3.jpg
How wildcards really work
Here's the secret. The shell expands the wildcard before the command even runs. So LS never sees the star. It receives the full list of matching names. That's why wildcards work with every command. CP, MV, RM, all of them. And it's why you should always check a pattern with LS, before using it with RM.
| key | value |
|---|---|
| The shell | expands the pattern |
| The command | gets the full list |
| Works with | cp, mv, rm, anything |
| Tip | test with ls first |
Summary
The star matches anything, the question mark matches one character, and brackets match a list. Always test a pattern with LS first. Next, let's tidy that downloads folder.
Key takeaways- * any characters
- ? one character
- [13] one of a list