Asterisk (*)
The asterisk matches many characters as well as no character. As an example, l*k will match: look, luck, lawl345essk and many more file names beginning with l and ending with k.
Question mark (?)
While the asterisk matches many characters, the question mark on the other hand matches only one character on its position. For example: l??k, matches look, luck and any four-letter word beginning with l and ending with k. It is worth mentioning that the two letters must not be lowercase so even lBGk can be matched using the question mark.
Brackets
There is this amazing bracketed group that is so interesting as well. The characters can be enclosed in square brackets [ ] and it will match using the characters in that set. For example, l[oc]k matched lok and lck. It can be implemented like this as well l[uk]g[oi]p which matche lugop, lugip, lkgop, and lkgip. This amazing group also allows you to specify a range for example a range of alphabets in the alphabetical set. For instance: l[a-z]k matches: lak, lbk, lck, ldk and any three letter word whose second letter is a lowercase.
What we have learnt above is used in the command prompt for example in listing specific files matching the letters you specify
A gook example is if you are searching for a file beginning with l or ending with .docx extension.
You just do:
# ls l*
# ls *.docx
Other examples are
# ls l??k
The above will bring up files like look, luck and others if they exist in the directory being probed
0 comments:
Post a Comment