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:
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.
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Using Python's pathlib Module (Course)
- Regular Expressions: Regexes in Python (Part 1) (Tutorial)
- Regular Expressions: Regexes in Python (Part 2) (Tutorial)
- Regular Expressions and Building Regexes in Python (Course)
- Python's pathlib Module: Taming the File System (Quiz)
- Regular Expressions: Regexes in Python (Part 1) (Quiz)
By Martin Breuss • Updated July 19, 2026