Typing ten file names is slow. Wildcards let one pattern stand for many names:
| Pattern | Matches |
|---|---|
* | any characters, any number of them (even none) |
? | exactly one character |
[abc] | one of the characters inside the brackets |
[0-9] | one character in that range |
So *.pdf is every name ending in .pdf, report-202?.pdf matches report-2025.pdf and report-2026.pdf, and IMG_010[12].jpg matches just the first two photos.
The shell does the matching
The command never sees the *. Before it runs, the shell swaps the pattern for the matching names, sorted. echo makes this visible:
echo downloads/*.pdfls downloads/IMG_*Two things follow from that:
- A pattern is matched against the directory it names.
*.jpglooks where you are;downloads/*.jpglooks in downloads. - If nothing matches, the pattern is passed on unchanged, and the command complains that a file called
*.jpgdoesn't exist.
Wildcards skip hidden files, and they're case-sensitive: *.jpg won't match HOLIDAY.JPG.
Before using a pattern with rm or mv, try it with ls or echo to see exactly which names it means.