Filtrowanie danych wyjściowych
$ ls -l filename.format
Notice that we have just provided the filename as a simple text-matching string filter and as expected ls provided us with the information of only that file.
When you specify the name of a specific file as the filter, the ls command only displays information about that file. You may not always know the exact filename you're looking for. The ls command also recognizes and uses standard wild card characters to match patterns within the filter:
A question mark (?) to represent one character
An asterisk (*) to represent any number of characters
The question mark can be used to replace exactly
one character anywhere in the filter string. For example:
$ ls -l se?up.sh
Similarly, the asterisk can be used to match zero or more characters. Here is an example:
$ ls -l *.sh
Quick Tip: You can place the asterisk or the question mark anywhere in your filter.
Using the asterisk and question mark in the filter is called file globing. File globing is the processing of pattern matching using wild cards. The wild cards are officially called "meta-character" wildcards. You can use more meta-character wildcards for file globing than just the asterisk and question mark.
You can also use brackets as shown below:
$ ls -l se[tc]up.sh
In this example, we used the brackets along with
two potential choices for a single character in that position,
t or c. The brackets represent a single character
position and give you multiple options for file globing.
You can also specify a range of characters,
such as an alphabetical range [a -t] :
$ ls -l se[a-t]up.sh
File globbing is such a broad topic that it deserves its own separate article to explain each metacharacter. When searching for files, file globing is a useful feature. It can also be used with other shell commands besides ls, such as grep, cut, tr, sed, gawk, rm, cp, and so on. You'll learn more about this in our future articles.
OHIOLee