05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Now this is just the first page of the man page—you can scroll through the rest using either<br />

the arrow keys (to move up and down one line at a time), or the spacebar to move through one<br />

page at a time. When you are done, you can exit the man page by pressing Q on the keyboard.<br />

grep<br />

TIP Computers have come a long way since the man page system was created, and while<br />

reading a man page in the terminal is relatively easy for short and simple commands, for more<br />

complex commands that can scroll through 100 or more screens, this isn’t ideal. One neat trick<br />

you can use is man -t command | open -f -a /Applications/Preview.app, which will open the<br />

entire man page of the command in Preview as a PDF file for immediate reading, printing, or<br />

saving. (The -t option converts the man page into a PostScript file, which you can then pipe<br />

into your Preview application, which converts the PostScript file into a PDF file as it opens it.<br />

Pipes are covered later.)<br />

The grep command searches through files or results for a specified string and then prints out the<br />

lines that contain a match. For example, using the preceding text file, we could print out all lines<br />

that contain “to” using the command grep to tomorrow. This is shown here:<br />

ln<br />

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ ls<br />

nothing tomorrow<br />

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ grep to tomorrow<br />

Tomorrow, and tomorrow, and tomorrow,<br />

Creeps in this petty pace from day to day<br />

The way to dusty death. Out, out, brief candle!<br />

ln is the command-line utility for creating links. While there are different ways of linking files,<br />

what we are most concerned with are symbolic (a.k.a. soft) links (more commonly referred to as<br />

aliases, or shortcuts in Windows). To create a symbolic link, you use ln with the -s link, followed<br />

by the name of the source file and then optionally the name of the linked file.<br />

NOTE ln by default creates a hard link, which is most likely not what you want, so it’s important<br />

to remember the -s option. For the technically curious, a hard link essentially creates a<br />

new file that shares its data with another (the source). If you edit one, the data will change in<br />

the other. If you delete one, the other will still remain with all the data intact. A symbolic link,<br />

on the other hand (like an alias or shortcut), creates a special “path” file that always refers to<br />

the original. If this original is deleted, the path is broken unless a new file of the same name<br />

replaces the original. A big difference in use is that a symbolic link can refer to a directory or a<br />

file on a different file system, while a hard link cannot.<br />

Let’s look at ln in action:<br />

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

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ ls<br />

macbeth/ nothing<br />

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ ls macbeth/<br />

soliloqy4<br />

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ ln -s macbeth/soliloquy4 tomorrow<br />

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ ls<br />

macbeth/ nothing tomorrow@<br />

<strong>Leopard</strong>:~/Documents/Shakespeare scott$ cat tomorrow<br />

Tomorrow, and tomorrow, and tomorrow,<br />

Creeps in this petty pace from day to day<br />

To the last syllable of recorded time,

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

Saved successfully!

Ooh no, something went wrong!