Which are the wildcars in Linux?

bash’s wildcard operators are *, ?, and the set operators, [SET] and [!SET]. * matches any string of characters and ? matches any single character. Suppose you have a directory containing the following files:

$ ls
zeis stopnm zic2xpm zipgrep zipsplit

znew zcmp zforce zip zipinfo zless

zdiff zgrep zipcloak zipnote zmore

The command ls zi* matches zic2xpm, zip, zipcloak, zipgrep,zipinfo, and zipsplit, but ls zi? only matches zip.

The set operators allow you to use either a range or a disjoint set of characters as wildcards. To specify an inclusive range of characters, use a hyphen between characters. For example, the set [a-o] includes all of the lowercase characters “a” through “o.” Use a comma to indicate a disjoint set, such as the range of characters between “a” and “h” and between “w” and “z”. In bash’s set notation, this range of characters could be specified
with “[a-h,w-z]”. If you want to look only for a few individual characters, such as all of the English vowels, the notation “[aeiou]” would do. The “!” prefixing a set means to include everything not in the set. So, an easy way to look for all of the consonants is to write [!aeiou]. The following examples illustrate using the set notation and also how you can use the wildcard operators with sets. To list all of the files in the directory above whose second letter is a vowel, you could write: $ ls z[aeiou]* This will match zeisstopnm, zip zipgrep, zipnote, zic2xpm,zipcloak, zipinfo, and zipsplit. On the other hand, to list the files that have only consonants as their second letter, use lsz[!aeiou]*, which matches zcmp, zdiff, zforce, zgrep, zless, zmore, and znew. The command, ls *[0-9]* matches only those filenames containing at least one numeric digit between zero and nine, which is zic2xpm in this case.

Posted on: 10/12/2009








0 Comments
If you want to leave a comment please Login or Register