Tuesday 22 October 2019

LPI 1: File Management Part 2

LPI Study Materials, LPI Guides, LPI Tutorial and Material, LPI Certifications, LPI Learning

Times will come when you will be required to search for files in a directory and you know that there are specific characters in those files that you can use to find them easily. Linux provides wildcards for such situation so that yo can match them easily and quickly. For example, you have an idea that there is file in current directory that ends with the word ‘fix’. To find the file fast, wildcards can be of huge benefit to you. There are these wildcards in Linux

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

Related Posts

0 comments:

Post a Comment