05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

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.

Wildcards<br />

Before moving on to more Darwin commands, we should have a quick lesson on wildcards and<br />

pattern matching. Wildcards are special symbols that when used with other commands can help<br />

limit or expand the results. Table 18-3 shows the three major wildcards and what they represent<br />

or match.<br />

Table 18-3. Darwin Wildcards<br />

Wildcard Definition (Matches)<br />

? The ? used on the command line matches any single character.<br />

* The * matches any one or more characters in a file name.<br />

[ ] The [ ] matches any characters listed between the brackets; this can include a series of<br />

characters as well—for example, [l-p] would match l, m, n, o, and p.<br />

To put this to use using what you learned previously, if we cd to /usr/bin and list out the<br />

contents using ls, we are struck with a rather large list of files (in this case mostly executable<br />

commands). Wildcards will allow us to selectively list out the directory contents in more manageable<br />

chunks. For example, if we just wanted to list the files that begin with v, we could use<br />

ls v*, like so:<br />

<strong>Leopard</strong>:/usr/bin scott$ ls v*<br />

vers_string* vi@ vim* vimtutor* vm_stat*<br />

vgrind* view@ vimdiff@ vis* vmmap*<br />

If for whatever reason we wanted to expand the search to include b and v, we could use<br />

ls [bv]*:<br />

<strong>Leopard</strong>:/usr/bin scott$ ls [bv]*<br />

b2m* bg* bzcat* bzless* vimtutor*<br />

banner* biff* bzcmp* bzmore* vis*<br />

basename* bison* bzdiff* vers_string* vm_stat*<br />

bashbug* bridget* bzegrep* vgrind* vmmap*<br />

batch* bsdmake* bzfgrep* vi@<br />

bbdiff* bspatch* bzgrep* view@<br />

bbedit* bspatch_apple@ bzip2* vim*<br />

bc* bunzip2* bzip2recover* vimdiff@<br />

NOTE Like most things in Darwin, the characters used within the square brackets are case<br />

sensitive, so [bv] would not match any Bs or Vs.<br />

Finally, if we wanted to list all files with two-letter names that begin with any letter in the<br />

alphabet from b to v, we could use ls [b-v]? and get the following:<br />

<strong>Leopard</strong>:/usr/bin scott$ ls [b-v]?<br />

bc* cc@ ci* dc* ex@ fg* ld* m4* nc* nm* pl* ri* su* ul*<br />

bg* cd* co* du* fc* id* lp* md* nl* od* pr* rs* tr* vi@<br />

Working with Files and Directories<br />

CHAPTER 18 INTRODUCING DARWIN AND THE SHELL 297<br />

While most people are perfectly happy and comfortable working with files and directories in the<br />

Finder, there are some times when it’s either necessary or advantageous to work with files in

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

Saved successfully!

Ooh no, something went wrong!