From LQWiki
Jump to: navigation, search

Wildcards are aids to searching. They are mostly used in finding files but also used in scripts and most programming languages for searching arrays and strings.

The most common wildcard is the '*' which means any number of symbols. Next most common is the '?' wildcard, which denotes a single occurence of any symbol. In some instances a '.' (period or fullstop) will act as a wildcard. There are others, that work on specific occasions, to denote NOT a character, or not a digit, or not a punctuation symbol.

For example, typing *.conf will return a list of all files in a directory (and/or depending on your search settings, subdirectories).

So searching this document for wild* would return all occurencies of 'wildcard' and 'wildcards', while searching for w?l?* would also return the instances of 'will'.


Wildcards will not work in some scenarios.

  • If you are an ordinary user and try to copy all files from /root to your home directory:
sudo cp /root/* .

it will not work because bash tries to replace the * by all files in /root, but you do not have permission to list those files.

  • If you use scp with wildcards, it cannot work at all:
scp user@somehost:* .

bash will try to replace * by all files, but is not aware these files reside on another computer. However, with newer distributions it works.

See also