Unix shells, such as /bin/sh and /bin/csh, automatically interpret words on the command line as expressions that stand for lists of filenames. This is known as filename globbing.

This is done by recognizing certain special 'wildcard' characters and interpreting them in a special way:

  • * stands for '0 or more arbitrary characters'
  • ? stands for '1 arbitrary character'
  • the [] are used to specify a range of possible characters, eg. *.[ch] expands to all files ending in .c or .h
  • files whose name starts with a . are not considered
  • if no matching filenames are found, the expression is used as it is
Some shells contain more features and sometimes, features are configurable. Globbing is also available elsewhere, programming languages often have a built-in function for it.

This feature provides a nice uniformity to Unix programs; they do not have to contain their own wildcard expansion, the shell does it for them. (Unfortunately, the parsing of command lines into options and arguments is not taken care of by the shell, and as a consequence, conventions in that area differ greatly from program to program.)

Note that filename globbing is fundamentally different from regular expressions: the * and choice in regular expressions are operators to build larger expressions from smaller parts and can be arbitrarily nested, whereas the wildcard expressions of filename globbing apply to filenames found on the file system.

The {} operator found in many shells is a regular expression operation: *.{c,h} expands to *.c *.h regardless of the existence of matching files; the result is matched against the actual filenames found on the system.