Basics

What is a glob pattern — and why src/**/*.js without quotes misses files

Illustration: a star-shaped stencil over rows of folders, with only some of the files showing through

Here's a one-minute experiment. A project has three files: src/x.js, src/a/y.js, src/a/b/z.js. Run this in plain sh:

echo src/**/*.js
# src/a/y.js

One file out of three. No error, the command succeeded. A formatter or linter with that argument will quietly process a third of your project. On your Mac everything will be fine, and it'll only break in CI.

Let's find out who's to blame. Spoiler: it comes down to two quote marks.

What a glob pattern is

A glob pattern is a template for file paths. Instead of listing files, you describe their shape.

The symbols are:

  • * — any characters, but inside one folder. *.js is every .js right here.
  • ** — any number of nested folders. src/**/*.js is every .js in src at any depth.
  • ? — exactly one character. file?.txt finds file1.txt.
  • [abc] — one character from the list.
  • {js,ts} — one of the options. *.{js,ts} means both .js and .ts.
  • ! — exclusion, where the tool supports it.

It resembles regular expressions but it's simpler and about something else. A glob describes paths. In it a dot is just a dot, and a star on its own means "anything."

The main trap: who expands the star

Two parties work in the terminal: the shell and the program. Either one can expand the star.

Without quotes the shell expands the pattern. The program receives a ready-made list of files. And sh and bash don't know ** by default: to them it's just *, meaning one folder. Hence one file out of three.

In quotes the pattern reaches the program untouched, and it finds the files itself:

prettier --write src/**/*.js     # expanded by the shell: some files
prettier --write "src/**/*.js"   # expanded by Prettier: all of them

Prettier's docs warn about this directly: don't forget the quotes around globs.

Now you can see why the bug is so sneaky. In zsh, the default on a Mac, ** works right away. But npm run on Linux runs scripts through sh. Everything's green locally, and in CI only some files get processed.

The same *.js means different things

Second surprise. The pattern looks identical and behaves differently.

  • .gitignore: *.log catches files at any depth. Both x.log and a/b/z.log. I checked with git check-ignore.
  • ESLint (files), tsconfig (include), GitHub Actions (paths): *.js means the root only. To go deeper, write **/*.js.

So .gitignore is the exception. And a slash changes the meaning there too: /build is only the folder at the root, while build with no slash is any folder with that name.

If an ESLint rule doesn't fire on nested files, this is almost always why.

The star doesn't see hidden files

The star skips files that start with a dot. In a folder with .env, echo * won't show it. Many file-search libraries behave the same way and have a separate dot: true setting.

That's how two disasters happen. cp * backup/ doesn't copy .env or .gitignore, so the backup is incomplete. And your archive of "the whole project" arrives without its configs. ls -A shows the hidden files in a listing.

Where this matters when you build with AI

Globs now steer agents too. In Cursor, a rule in .cursor/rules can be tied to files:

---
globs: ["src/**/*.tsx"]
alwaysApply: false
---
Write components as functions, no classes.

Write *.tsx instead and the rule may not attach to nested files, so the agent writes whatever it wants. You won't know why: there's no error, the rule just stays silent. Searching a project by hand uses globs too — see how to find code in a big project.

How to check a pattern in 10 seconds

Don't guess, ask directly:

  1. What the shell will expand — put echo before the pattern: echo src/**/*.js.
  2. Why Git ignores a file — git check-ignore -v path/to/file. It shows the .gitignore line that matched.
  3. What the tool will pick up — many can show the list. TypeScript has tsc --listFilesOnly, ESLint has eslint --debug.

What's the difference between * and **?

* works inside one folder, and ** goes through any number of nested ones. src/*.js won't see src/a/y.js. src/**/*.js will.

Why does zsh say no matches found?

In zsh, a pattern with no matches is an error and the command doesn't run. In bash it's passed along as text. Quotes solve this one too.

Is a glob a regular expression?

No. A glob is simpler and describes paths. As a regex, *.js would mean something else entirely: there a star means "repeat the previous character." You can't swap one for the other.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →