Wildcard characters
When you need to query the desired results with a command, the user does not have to find all of them and can use the shell wildcard character. The wildcard character of the shell command is the following table
Symbol |
Meaning |
Instance |
* |
Any character of any length |
A*b, matching such as a3b, ACB, AABC, A/b, a123,/b. |
? |
Match any single character |
A?b, matching such as A1B, ACB, A, b |
[ ] |
Matches any character in the specified range |
A[xyz]b, matching such as AXB, Ayb, Azb |
[ - ] |
Match any one character range |
A[a-z]b, matching such as Ayb, ACB, ADB, AUB |
[^...] |
Matches all but the specified characters |
A[^0-9]b, except a0b-a9b, all the other matches. |
Special Character Set
POSIX (The Portable Operating System Interface) adds special character classes to the character encodings in different countries, such as [: Alnum:] is another notation for a-za-z0-9. You can place them in the [] number to be a regular expression, such as [a-za-z0-9] or [[: Alnum:]]. grep under Linux supports POSIX character classes in addition to Fgrep.
[: Space:]: all whitespace characters
[:p UNCT:]: All punctuation
[: Lower:]: All lowercase letters
[: Upper:]: All uppercase letters
[:d Igit:]: All numbers
[: Alnum:]: All numbers and letters
[: Alpha:]: All letters
[:p rint:]: All non-whitespace characters (including spaces)
Example:
1. Display all files or directories starting with the letter in the/tmp/ky directory
650) this.width=650; "title=" ls "alt=" wkiol1pbdelgjrj-aabwsh6byvg689.jpg "src=" http://s3.51cto.com/wyfs02/M00/3C/ 7c/wkiol1pbdelgjrj-aabwsh6byvg689.jpg "/>
2. Display a file or directory with a digit in the middle of the/tmp/ky directory starting with a letter and ending with a lowercase letter
650) this.width=650; "style=" WIDTH:465PX;HEIGHT:37PX; "title=" LS2 "border=" 0 "hspace=" 0 "alt=" Wkiol1pbd6mabxa2aaa-gdoseko899.jpg "src=" http://s3.51cto.com/wyfs02/M01/3C/7D/ Wkiol1pbd6mabxa2aaa-gdoseko899.jpg "width=" 465 "height=" Notoginseng "/>
Note: The meaning of the middle plus * in the command line is that * denotes any character of any length or 0, so add * if you don't know what is between two characters
3, displays the/tmp/ky directory starts with the letter, ends with a lowercase letter, the middle is the space file or the directory
650) this.width=650; "title=" LS3 "alt=" wkiol1pbemkytbmcaaa64nwg6fe527.jpg "src=" http://s3.51cto.com/wyfs02/M02/3C/ 7e/wkiol1pbemkytbmcaaa64nwg6fe527.jpg "/>
4. Displays the file or directory with the letter ending in the/tmp/ky directory and the symbol in the middle.
650) this.width=650; "title=" Ls4 "alt=" wkiom1pb29vrdtciaabcs2xao-u261.jpg "src=" http://s3.51cto.com/wyfs02/M00/3C/ B2/wkiom1pb29vrdtciaabcs2xao-u261.jpg "/>
5. Display all files or directories with a small letter ending with L in the/var directory, and one digit in the middle;
# ls/var/l*[[:d Igit:]]*[[:lower:]]
This file or directory does not exist and can be created in advance to detect
notice here [[:d Igit:]] For what is a double-square bracket, because, [:d Igit:] is to represent a collection, and to represent a range of characters, you must add brackets. So that's [[:d Igit:]], fixed format
6. Displays files or directories that start with any digit and end with a non-digit in the/etc directory;
# ls-d/etc/[[:d igit:]]*[^[:d igit:]]
This file or directory does not exist and can be created in advance to detect
7, display in/etc directory, start with a non-letter, followed by a letter and any other characters of any length of the file or directory;
# ls-d/etc/[^[:alpha:]][[:alpha:]]*
This file or directory does not exist and can be created in advance to detect
8, copy/etc directory, all start with P, non-numeric end of the file or directory to the/tmp/mytest1 directory;
# Mkdir/tmp/mytest1
# cp-r/etc/p*[^[:d igit:]]/tmp/mytest1
9, copy the/etc/directory, all files or directories ending with. D to the/tmp/mytest2 directory;
# Mkdir/tmp/mytest2
# Cp-r/etc/*.d/tmp/mytest2
10. Copy all files in the/etc/directory starting with L or M or N and ending with. conf to the/TMP/MYTEST3 directory;
# MKDIR/TMP/MYTEST3
# Cp-r/etc/[lmn]*.conf/tmp/mytest3
This article is from the "Fish" blog, please be sure to keep this source http://kyfish.blog.51cto.com/1570421/1437514