File wildcard
I. document wildcards
Wildcards are mainly used to find matching characters by setting certain conditions.
* match any character, including 0
? Match any single character
~ username: matches the home directory of username
Cp / root/file1 ~ tom/ #: copy the file1 file to the tom user's home directory
~ match to the current home directory
[abc] matches to any letter in abc
[^ abc] matches to any character except abc
[0-9] matches any number between 0-9
[amurz] matches any letter between aAbBcC-z
[Amurz] matches any letter between AbBcC-zZ
[: alpha:] matches any letter
[: digit:] matches any number
[: alnum:] matches any letter or number
[: upper:] matches any uppercase letter
[: lower:] matches any lowercase character
[: punct:] matches any symbol
[: space:] matches any space
Exercise:
1. Display all files or directories in the / var directory that begin with I, end with a lowercase letter, and have at least one digit in the middle
Ls / var/I* [1-9] * [[: lower:]]
2. Display files or directories under the / etc/ directory that begin with any number and end with a non-number
Ls / etc/ [0-9] * [^ 0-9]
3. Display files or directories in the / etc/ directory that begin with a non-letter, followed by a letter and any other characters of any length.
Ls / etc/ [^ [: alpha:]] [: alpha:] *
4. Display all files or directories under the / etc/ directory that begin with m and end with a non-numeric end
Ls / etc/m* [^ 0-9]
5. Show all files or directories ending in .d in the / etc/ directory
Ls / etc/*.d
6. Show all files or directories in the / etc/ directory that end with .conf and begin with mreco ndir r rep.
Ls / etc/ [mnrp] * .conf