Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Wild Cards

July 19, 1998

There are several tools that are useful when submitting commands to the kernel via the shell. These tools help make tasks more efficient. One such tool is the wild card.

The wild cards that you will use most often include the asterisk (*), the question mark (?) and the brackets ([])

The asterisk is used to match any character zero or more times. For example, if we modify the "ls" command used in the last section, we can filter the output for only files starting with "s" using the command ls -l s*

The question mark on the other hand, is used to match any single character. Thus ls -l ???? will match any file with a name four characters long such as temp or "temp"

Finally, brackets are used to specify ranges or internal sets. Thus you can specify which characters from within a set you are looking for such as in the following case which matches any even number below 10: [02468]

Below is a table that shows some of the more common uses for wildcards with the "ls" command that you might use.

Example Result
ls index* Matches any file beginning with the characters "index" including index.html, index.bak, index.cgi
ls *.html Matches any file ending in ".html" such as index.html or test.html. (Note however, that this would not match index.html.bak. To do that you would need *.html*)
ls a*.html matches all the HTML files starting with the letter "a"
ls ?? Matches any file with a filename of two characters such as "aa" or "bb"
ls ?.html Matches all HTML files with a single character name such as a.html or 1.html. 12.html would not match
ls [abcd]??.html Matches any file starting with "a", "b", "c" or "d" followed by any two characters, and followed by a .html ending.
ls part[0-9].doc Matches all .doc from part 1 through part 9 such as part4.doc.
ls part[A-Z].doc Matches all .doc from part A through part Z such as "partM.doc". Notice that this is case sensitive so it would not match "partm.doc". To do that, you would need [a-z] or [a-zA-Z]

Executing Utilities
Introduction to UNIX for Web Developers | Table of Contents
Input, Output, and Redirection


Up to => Home / Internet / UNIX / Intro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers