10

What is the difference between globbing and wildcards, are they two terms for the same thing, or are they different?

2
  • Have you any example code you have tried?
    – ImHere
    Dec 28 '17 at 4:02
  • 3
    *.txt is a glob pattern where * is a wildcard. The terms are often used interchangeably though.
    – jesse_b
    Dec 28 '17 at 4:04
7

Glob is an alternate name for "Pathname Expansion" as described in the dash (sh) or bash manual (ksh calls it "Filename Expansion"). It is clearly defined in the manuals.

After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern

Wildcard is a term for the same concept (one character is used as a pattern standing for several posible characters) but it is not so clearly defined. Wildcard characters are * and ? used in globbing.

An asterisk (``*'') matches any string of characters. A question mark matches any single character.

2

Globbing is a practice of using wildcard characters like '*', '?', and '$', to trigger pathname expansion. Also, have a look at the Linux man page for globbing.

It is usually safe to assume that the shell environment you're working with supports globbing. Unless you're using FTP, or old style DOS, or some kind of shell that doesn't support pathname or Filename expansion. However, those wildcard characters ('[' is a wildcard in Linux) may have different meanings or operations in different contexts.

2
  • 2
    What is $ in pathname expansion ?
    – ImHere
    Dec 28 '17 at 4:36
  • DOS's shell, or CMD shell doesn't have to support globbing. The commands support them e.g. DIR *.*
    – barlop
    May 6 '20 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.