Skip to main content
0 reactions

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

SyntaxBash
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, rm and 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

TerminalBash
ls photos/*.jpg
OutputPlain text
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

TerminalBash
ls photos/*2026*
OutputPlain text
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.

0 comments