x
Loading
 Loading
Hello, Guest | Login | Register

Wildcards Gone Wild

When you type a filename on the command line (at a shell prompt), you may use filename completion to save time and typing. A popular feature, filename completion lets you type the first few letters of a file or directory name and use the TAB key to ask the shell to fill in the rest.

When you type a filename on the command line (at a shell prompt), you may use filename completion to save time and typing. A popular feature, filename completion lets you type the first few letters of a file or directory name and use the TAB key to ask the shell to fill in the rest.

The shell can also complete file and pathnames non-interactively by using wildcards to do pathname expansion. For example, the command line rm *.o removes (with the wildcard *) all files in the current directory whose name ends with .o. Wildcards are much more powerful and flexible than filename completion, and most shells have their own advanced wildcards that do powerful and sophisticated things.

This article assumes that you’ve used the basic wildcards * (matches anything), ? (matches any single character), [xyz] (matches any of x, y, or z, and [v-z] (which matches any letter in the range v through z, inclusive). Let’s look what happens underneath the surface, so you can be confident of getting the result you want. Along the way, let’s also take a look at a handy function that makes wildcards work more like filename completion, letting you see an expanded command line before you run it. Time to dig in!

How Wildcards Work

When a shell reads a command line (either from a shell prompt or a shell script), it goes through a series of steps to interpret what it finds. One of the steps…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. KDE 4.4: Does It Work Yet?
  2. Writing Custom Nagios Plugins with Python
  3. Power Up Linux GUI Apps
  4. Tweeting from the Command Line with Twyt
  5. When Memory Serves You: Using ramfs and tmpfs
Follow Linux Magazine
Rackspace