Preface
In uselinux
When usingLinux
built-in
Orderfind
、ls
If you do not know the full name and only use one or a few characters to operate, you can use wildcard characters to replace and complete the characters and strings of the remaining objects.
The following article introduces the relevant knowledge and usage methods of wildcard characters used by the author during his work.
1. Wildcards and their classifications
- Regarding what wildcard characters, the following page introduces this part very well, and will not elaborate on it.
Introduction | path |
---|---|
Baidu entry | link |
notes | The difference between Linux wildcards and regular expressions and detailed explanations:link |
- A summary of wildcard knowledge part
symbol | Interpretation | illustrate |
---|---|---|
* |
Represents zero or more characters | Underscore’_', decimal point’.’, space’ are also characters, the same below |
? |
One character | |
[] |
Brackets, match any of the characters in the braces | ([abc] It means that a, b and c can be matched.[abc] Also use commas in brackets.[abc] Equivalent to[a,b,c] ) |
^ |
same! , only in brackets[] Used in, indicating that any character in brackets does not match |
([!abc] Indicates that a, b, c does not match) |
{} |
Match any of the character combinations in braces | ({ab,c,de} Indicates matching any one of ab, c, and de){} Is it a wildcard? |
Characters: include letters, numbers, operators, punctuation marks and other symbols, as well as some functional symbols. From the character Baidu entry1
- In addition, specify matching numbers, letters (caps, lowercase), numbers or letters, dots or underscores, etc.:
symbol | Interpretation | illustrate |
---|---|---|
[:digit:] | Match numbers | Match only one |
[:lower:] | Any lowercase letters | Match only one |
[:upper:] | Any capital letters | Match only one |
[:alpha:] | Any letter | Match only one |
[:alnum:] | Any letter or number | Match only one |
[:space:] | A space | Match only one |
[:punct:] | Indicates a symbol | Can it be various symbols on the keyboard, including but not limited to @, #, _, \, (,), ^, &, ~, .,? etc symbols, but do not include spaces, numbers, and letters |
Notes:
1. All the above matches match one;
2. Use double brackets, in this form
[[:digit:]] [[:lower:]] [[:upper:]] [[:alpha:]] [[:alnum:]] [[:space:]] [[:punct:]]
2. Wildcard examples and cases
The linux shebang used is sh or bash, and cannot use tcsh or csh
The files used are:
# View the filesh-4.2$ ls * 1 1#2 '1(2' '1*2' 12 '1?2' '1\2' 1_2 1~2 A A_ '1 2' '1&2' '1)2' 1.2 '1=2' 1@2 '1^2' 1ls 2 A.
Example:
sh-4.2$ ls 1 1#2 '1(2' '1*2' 12 '1?2' '1\2' 1_2 1~2 A A_ '1 2' '1&2' '1)2' 1.2 '1=2' 1@2 '1^2' 1ls 2 A. sh-4.2$ ls * 1 1#2 '1(2' '1*2' 12 '1?2' '1\2' 1_2 1~2 A A_ '1 2' '1&2' '1)2' 1.2 '1=2' 1@2 '1^2' 1ls 2 A. ## [[:digit:]][[:punct:]]? Represents numeric symbol characterssh-4.2$ ls [[:digit:]][[:punct:]]? 1#2 '1&2' '1(2' '1)2' '1*2' 1.2 '1=2' '1?2' 1@2 '1\2' '1^2' 1_2 1~2
### ?? sh-4.2$ ls ?? 12 A. A_
sh-4.2$ ls 1 1 sh-4.2$ ls 1* 1 '1 2' 1#2 '1&2' '1(2' '1)2' '1*2' 1.2 12 '1=2' '1?2' 1@2 '1\2' '1^2' 1_2 1ls 1~2 sh-4.2$ ls 1? 12
### []A certain character insh-4.2$ ls [12] 1 2 sh-4.2$ ls [1A] 1 A ### [!1A] is not a character of 1 and Ash-4.2$ ls [!1A] 2
### {} character combination, separated by commassh-4.2$ ls {[1A],2} 1 2 A sh-4.2$ ls {[1A],A_} 1 A A_ sh-4.2$ ls {[[:digit:]],A_} 1 2 A_ sh-4.2$ ls {[[:digit:]][[:digit:]],A_} 12 A_
### [[:alnum:]] and [a-z0-9A-Z] synonymoussh-4.2$ ls [[:alnum:]] 1 2 A sh-4.2$ ls [[:upper:]] A
### sh-4.2$ ls A.[[:alpha:]][[:alpha:]][[:alpha:]] ### . Points are one of puncts, but do not include spacessh-4.2$ ls A[[:punct:]][[:alpha:]][[:alpha:]][[:alpha:]]
### ? Question marks can represent a charactersh-4.2$ ls ???? '1 2' sh-4.2$ ls [[:digit:]][[:punct:]]? 1#2 '1&2' '1(2' '1)2' '1*2' 1.2 '1=2' '1?2' 1@2 '1\2' '1^2' 1_2 1~2 ### Spaces are used to match [[:space:]]sh-4.2$ ls ?[[:space:]][[:space:]]? '1 2'
Notes:
When using [[:digit:]] [[:lower:]] [[:upper:]] [[:alpha:]] [[:alnum:]] [[:space:]] [[:punct:]]], if the same match exceeds once, it can be reused.
For example:[[:digit:]][[:digit:]]
It's legal, but[[:digit:]]+
It's not possible
Summarize
This section is a summary of the types and use cases of wildcard characters,Linux
During the use of the wildcard characters, mastering them can often achieve twice the result with half the effort.
The above is personal experience. I hope you can give you a reference and I hope you can support me more.