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.

298<br />

CHAPTER 18 INTRODUCING DARWIN AND THE SHELL<br />

Darwin. Of course, like all things before you are able to unleash the power of Darwin, you need<br />

to learn a few basic commands for working with files and directories. These basics are shown<br />

and described in Table 18-4.<br />

Table 18-4. File and Directory Management Commands<br />

Command Usage Description<br />

cat cat filename The cat command lists the contents of a file. This<br />

command was originally written to perform concatenation<br />

functions, so if used improperly, this could have<br />

unexpected results.<br />

head head [-n #] filename The head command allows you to display just the<br />

beginning of a long file using the -n option followed<br />

by the number of lines you wish to view.<br />

tail tail [-n #] filename The tail command allows you to display just the end of a<br />

long file using the -n option followed by the number of<br />

lines you wish to view.<br />

cp cp filename filecopy cp creates copies of files.<br />

mv mv filename newfilename mv is interesting in that it is used both to move files from<br />

one location to another and to rename files.<br />

rm rm filename rm permanently and immediately removes a file (or files).<br />

mkdir mkdir newdirectory mkdir is used to create new directories.<br />

rmdir rmdir directory rmdir is a special command used to delete directories. It’s<br />

a safer option than rm in that it will not delete a nonempty<br />

directory (which at times makes it more frustrating as well).<br />

touch touch filename touch will create a new empty file. (If the file, however,<br />

already exists, touch will merely alter the date it was last<br />

accessed.)<br />

CAUTION Irresponsible uses of rm can result in very bad things happening—for example, if<br />

you happen to be utilizing root privileges (which, in general, you probably shouldn’t), and happen<br />

to type rm -R /* at the command line, your system will immediately begin to delete itself<br />

and everything contained within it until it deletes enough of itself that it can’t continue . . .<br />

ever. (By the way, the -R option stands for recursive, a handy option found in many<br />

commands.)<br />

To illustrate how all of these work, I’ve created a test file named soliloquy4 in a directory<br />

named Shakespeare.<br />

First we can use the cat command to view the file:<br />

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

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

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

To the last syllable of recorded time,<br />

And all our yesterdays have lighted fools<br />

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

Life's but a walking shadow, a poor player

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

Saved successfully!

Ooh no, something went wrong!