25.03.2013 Views

Copyright Sams Teach Yourself Shell Programming in 24 Hours

Copyright Sams Teach Yourself Shell Programming in 24 Hours

Copyright Sams Teach Yourself Shell Programming in 24 Hours

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Us<strong>in</strong>g the * Wildcard<br />

The simplest form of filename substitution is the * character. The * tells the shell to match zero or more<br />

occurrences of any character. If given by itself, it matches all filenames. For example, the command<br />

$ ls *<br />

lists every file and the contents of every directory <strong>in</strong> the current directory. If there are any <strong>in</strong>visible files or<br />

directories, they are not listed. You need to specify the -a option to ls, as described <strong>in</strong> Chapter 3, "Work<strong>in</strong>g<br />

with Files."<br />

Us<strong>in</strong>g the * character by itself is required <strong>in</strong> many cases, but its strength lies <strong>in</strong> the fact that you can use it to<br />

match file suffixes, prefixes, or both.<br />

Match<strong>in</strong>g a File Prefix<br />

To match a file prefix, use the * character as follows:<br />

command prefix*<br />

Here, command is the name of a command, such as ls, and prefix is the filename prefix you want to<br />

match. For example, the command<br />

$ ls ch1*<br />

matches all the files and directories <strong>in</strong> the current directory that start with the letters ch1. The output is<br />

similar to the follow<strong>in</strong>g:<br />

ch10-01 ch10-02 ch10-03 ch11-01 ch11-02 ch11-03<br />

By vary<strong>in</strong>g the prefix slightly, you can change lists of files that are matched. For example, the command<br />

$ ls ch10*<br />

generates the follow<strong>in</strong>g list of files on your system:<br />

ch10-01 ch10-02 ch10-03<br />

You can vary the suffix until it matches the list of files that you want to manipulate.<br />

Match<strong>in</strong>g a File Suffix<br />

To match a file suffix, you use the * character as follows:<br />

command *suffix

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!