Wildcards

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search

This article is a stub. You can help us by expanding it.

Wildcards is one of the most important features of Bash shell. It allows you to select a group of files. For example you can select all C programming files in a GUI file manager with mouse. To select all C programming files in a Bash shell you use wildcards. In short wildcards are nothing but special characters that allows you to select a group of files that matches certain pattern. A patter can be as expressed:

  1. All C programming files - *.c
  2. All C header files - *.h
  3. All Perl files - *.pl
  4. All Perl files starting with an alphabet 'c' - c*.pl

Wildcard and Filenames

In Linux or UNIX, a wildcard character can be used to substitute for any other character or characters in a string. Usually, you use a wildcard character when specifying file names (or paths).

Commonly Used Wildcards In Bash

Following are most most commonly used wildcards in Bash shell:

  1. Star Wildcard (*) - The asterisk character ("*") substitutes for any zero or more characters.
  2. Question Mark Wildcard (?) - The question mark ("?") substitutes for any one character.
  3. Square Brackets (range wildcard) - Rages of characters enclosed in square brackets ("[" and "]") substitute for all the characters in their ranges.