What is Glob?

Glob is a pattern matching syntax used to specify sets of filenames or paths using wildcard characters. It originated in Unix shells and is now widely used in programming languages, build tools, and file systems.

Quick Facts

Full NameGlob Pattern / Globbing
Created1971 (Unix glob command)
SpecificationOfficial Specification

How Glob Works

Glob patterns use special characters to match multiple files or directories. The asterisk (*) matches any sequence of characters, question mark (?) matches any single character, and brackets [] match character sets. Double asterisk (**) in extended glob syntax matches directories recursively. Glob is simpler than regular expressions but sufficient for most file matching needs. It's used in .gitignore files, build configurations, and command-line operations.

Key Characteristics

  • * matches any sequence of characters (except path separator)
  • ? matches exactly one character
  • [] matches any character in the set
  • ** matches directories recursively (extended glob)
  • ! or ^ negates a character set
  • Simpler syntax than regular expressions

Common Use Cases

  1. File selection in build tools (webpack, gulp)
  2. .gitignore patterns for excluding files
  3. Command-line file operations (ls *.txt)
  4. Test file discovery in testing frameworks
  5. Asset bundling and copying in build processes

Example

Common Glob Patterns:

*.js          - All JavaScript files
**/*.test.js  - All test files in any subdirectory
src/**/*      - All files under src/ recursively
*.{js,ts}     - All .js and .ts files
[abc].txt     - a.txt, b.txt, or c.txt
file?.txt     - file1.txt, fileA.txt, etc.
!node_modules - Exclude node_modules

Related Tools on QubitTool

Related Concepts