Wildcards
From Linux Shell Scripting Tutorial - A Beginner's handbook
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:
- All C programming files - *.c
- All C header files - *.h
- All Perl files - *.pl
- 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:
- Star Wildcard (*) - The asterisk character ("*") substitutes for any zero or more characters.
- Question Mark Wildcard (?) - The question mark ("?") substitutes for any one character.
- Square Brackets (range wildcard) - Rages of characters enclosed in square brackets ("[" and "]") substitute for all the characters in their ranges.