A * in a file name stands for any characters, so one pattern can match many files: *.jpg matches every name that ends in .jpg.
Every command and output on this page is real, run in Terminal with zsh 5.9 on macOS 26.
Syntax
command folder/*pattern*
*: any characters, including none. Put it before, after or around the part every name shares.- The shell turns the pattern into the list of matching names before the command runs, so it works with
ls,cp,rmand other commands.
See Filename Generation (opens in a new tab) in the zsh manual.
The Example
A folder named photos with trip-2025.jpg, trip-2026.jpg and notes.txt.
Step 1: Match Every .jpg File
ls photos/*.jpg
photos/trip-2025.jpg photos/trip-2026.jpg
notes.txt doesn’t end in .jpg, so it isn’t listed.
Step 2: Match a Part of the Name
ls photos/*2026*
photos/trip-2026.jpg
With a * on both sides, the pattern matches any name with 2026 anywhere in it.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A pattern that matches nothing, such as ls photos/*.png | zsh stops before running the command: zsh: no matches found: photos/*.png | Check the pattern with ls first |
FAQ
Does * also match hidden files?
Not in zsh by default: names that start with a dot need the dot in the pattern, such as .*.
Conclusion
Use * for the part of the names that changes, and check the pattern with ls before using it with a command that changes files.
Additional Resources
- Filename Generation (opens in a new tab) (zsh manual)
- Pattern Matching Notation (opens in a new tab) (POSIX standard)
macOS is a trademark of Apple Inc.
0 comments