Skip to content

glob pattern

A glob pattern is a string that uses wildcard characters to match a set of filenames or paths, expanding one compact expression into every name that fits its shape.

The technique comes from early Unix, where a program named /etc/glob expanded wildcards in command arguments before handing the results to a command. The name is short for global, and the idea spread from the shell into the many tools that need a lightweight way to select files by name. A small set of metacharacters does the work:

  • * matches any run of characters, including an empty one, but stops at a path separator.
  • ? matches exactly one character.
  • [abc] matches a single character from the bracketed set, and [a-z] matches one from a range.
  • [!abc] matches a single character that is not in the set.

A few conventions extend this core. A leading dot must be matched explicitly, so * skips hidden files, and the ** globstar, where supported, descends through nested directories.

To see these rules in action, type a pattern below and watch which filenames in the sample set it selects:

Interactive diagram — enable JavaScript to view.

A glob is deliberately weaker than a regular expression, with no notion of repetition counts or alternation, which keeps the syntax small and readable for the common job of picking files. Glob matching turns up in Unix shells, .gitignore rules, and build tools, and Python provides it through the glob and pathlib modules.

Python 3 "pathlib" Module: Taming The Filesystem

Tutorial

Python's pathlib Module: Taming the File System

Python's pathlib module enables you to handle file and folder paths in a modern way. This built-in module provides intuitive semantics that work the same way on different operating systems. In this tutorial, you'll get to know pathlib and explore common tasks when interacting with paths.

intermediate python stdlib

For additional information on related topics, take a look at the following resources:


By Martin Breuss • Updated July 19, 2026