Fundamentals of the ten-year OPS series-Linux
Zeng Lin
Contact: [Email protected]
Website: www.jplatformx.com
Copyright: Please do not reprint the article without permission
First, Introduction
We often have to execute command-line programs under the shell, and these command-line programs often use filenames, so the shell provides special characters to help you quickly specify or filter a set of filenames. These special characters are referred to as "wildcards". Wildcards (also known as file name substitution) allow the user to select a file name based on a character pattern. Wildcard characters can be used with any command that uses a file name parameter. and wildcard characters can not only work in the command-line program, but also in the GUI program.
Second, wildcard characters
The following table provides common wildcard characters, wildcard character classes, and instances in which wildcards are used in practice.
Wildcard character Descriptor:
Wildcard characters |
Matching items |
* |
Matches any number of characters (including 0 and 1) |
? |
Match any single character (not including 0) |
[Characters] |
Match any character that belongs to a character set |
[!characters] |
Match any character that is not part of a character set |
[[: Class:]] |
Match any of the characters that belong to the specified character class |
Wildcard character class table:
Character class |
Matching items |
[: Alnum:] |
Match any one letter or number |
[: Alpha:] |
Match any one character |
[:d Igit:] |
Match any number |
[: Lower:] |
Match any one lowercase letter |
[: Upper:] |
Match any one uppercase letter |
Examples of wildcard characters:
Form |
Matching items |
g* |
Any file that begins with G |
B*.txt |
Any file beginning with B with any number of characters in the middle and ending in. txt |
Data??? |
Any file that starts with data, followed by a 3 character |
[abc]* |
Any file that begins with either of the ABC |
BACKUP. [0-9] [0-9] [0-9] |
Start with backup. Any file that is immediately followed by a 3-digit number |
[[: upper:]]* |
Any file that begins with an uppercase letter |
[! [:d Igit:]] * |
Any file that does not start with a number |
*[[:LOWER:]123] |
Any file that ends in lowercase letters or numbers 1, 2, 3 |
(004) Linux shell wildcard