Site icon JD Bots

How to Match Many Files with a Wildcard in the Terminal

Card titled The * Wildcard, labelled shell basics, with three ticked lines: ls photos/*.jpg and the two files it matches, trip-2025.jpg and trip-2026.jpg.

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

Syntax

command folder/*pattern*

See Filename Generation 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

Terminal

ls photos/*.jpg

Output

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

Terminal

ls photos/*2026*

Output

photos/trip-2026.jpg

With a * on both sides, the pattern matches any name with 2026 anywhere in it.

Common Mistakes

MistakeWhat happensDo this instead
A pattern that matches nothing, such as ls photos/*.pngzsh stops before running the command: zsh: no matches found: photos/*.pngCheck 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

macOS is a trademark of Apple Inc.

Exit mobile version