Home arrow Programming Fundamentals arrow Working with Wildcards

Language Translator

Hacking Zone

Hacking Tools
Attacking

Configure Windows

Windows Configuration

Mix Tutorials

Asterisk
Website Building

Novels

Mix Novels

Human Personality

Body Language
Working with Wildcards Print E-mail
Article Index
Working with Wildcards
Page 2
Page 3
Page 4

Working with Wildcards



Shells support a rich set of wildcards to help work with files. Awildcard is an expression that the shell uses to expand to a number of file names&mdashthat is, to all files that match the expression. Wildcards are often called globs. The use of globs is called globbing.

The * Wildcard


>
>

The main wildcard is a star, or asterisk (*), character. (Java programmers sometimes call this a splat.) A star alone matches anything and nothing, sort of Zen-like. Typically, you need to pair a star with some other characters to form a more specific expression. For example, *.txt matches all file names ending with .txt, including all of the following:

.txt

a.txt

a_very_long_name.txt

A_FILE_NAME_WITH_UPPERCASE_LETTERS.txt

The * means that you don&rsquot care what letters there are before the .txt.

Typically, an expression such as *.txt will match all text files. You can refine the wildcard expression further. For example, a*.txt matches all file names that start with a lowercase letter a and end with .txt. Again, the * means you don&rsquot care about any letters in between. Using the files from the previous list, a*.txt would match just the following:

a.txt

a_very_long_name.txt
>
> If you want files that start with an uppercase A or a lowercase a and end with .txt, use the expression [Aa]*.txt. This expression would match the following files:

a.txt

a_very_long_name.txt

A_FILE_NAME_WITH_UPPERCASE_LETTERS.txt

You can use the star more than once&mdashfor example, with the expression a*v*.txt. This expression would match only one file in the example list of files:

a_very_long_name.txt

On MS-DOS, each program has to support wildcards on its own. A few DOS commands, such as DIR, support a limited number of wildcard expressions. This is very different with Unix and Linux, as the shell supports the wildcard expressions so each program doesn&rsquot have to.



 
< Prev   Next >
Your Ad Here

Donate us!!

Enter Amount:

RSS socialnet

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits