Globbing is a programming concept that involves the use of wildcards and special characters to match and filter. Glob patterns are similar to regex patterns, but simpler and limited in scope.

This guide is based on Bash and ZSH.


Some links copied from begin/globbing



Wildcard matches are used alongside literals.

Basic wildcards:

  • * - Match any character zero or more times.
  • ** - Match any character zero or more times, including / unlike the others.
  • ? - Match any single character one time.
  • [...] - Match any of the characters. e.g. [abc], [123]
  • [X-Y] - Match a range. e.g. [0-9a-z], [\w]


  • */* - will match foo/bar.
  • * will match all files and directories in the current directory.
      echo *
      ls *
      for P in *; do echo $P; done


Wildcard expansion can be done. This can be previewed with echo but might be used with ls.

echo foo/{bar,baz}
# => foo/bar foo/baz

POSIX character classes

You can also use named ranges, such as:

  • [::alpha::] for any letter.
  • [::alnum::] for any letter or number.
  • [::lower::] for any lowercase character.


Match a1 but not aa with:


Match hidden characters

Bash 4

shopt -s dotglob


setopt dotglob


See the Globstar section.