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.

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

both types of code in your application. lipo allows you to take a universal application and<br />

“thin” it so that the resulting application will only run on one architecture. The advantage of this<br />

is that you can free up significant amounts of space on your hard drive by thinning your application.<br />

For example, if we delve into Sherlock.app (which in Darwin will appear as a directory,<br />

since most <strong>OS</strong> X applications are actually application bundles, or special directories containing<br />

all the pieces of the application) to the actual executable (/Applications/Sherlock.app/Contents/<br />

<strong>Mac</strong><strong>OS</strong>/Sherlock), we can see that its default size is 570 KB. If we run lipo using the -thin i386<br />

option (since I’m using an Intel machine—if you are on a PowerPC computer, you would replace<br />

the i386 with ppc), we can shrink this file down to around 280 KB. That’s a 50 percent savings of<br />

disk space by stripping away parts I don’t need and will never use on this computer! lipo will<br />

thin a file by taking the initial universal binary executable, followed by the thin option, followed<br />

by the output option and the name of the output file. lipo always makes a copy of the original,<br />

and it’s not a bad idea to back up the original file until you are sure that the thinned file works<br />

without error. An example of running lipo on Sherlock could look something like this:<br />

<strong>Leopard</strong>:~ scott$ cd /Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong>/<br />

<strong>Leopard</strong>:/Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong> scott$ ls<br />

Sherlock*<br />

<strong>Leopard</strong>:/Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong> scott$ du -hsk Sh*<br />

572K Sherlock<br />

<strong>Leopard</strong>:/Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong> scott$ lipo Sherlock -thin i386 ➥<br />

-output Sherlock.i386<br />

<strong>Leopard</strong>:/Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong> scott$ du -hsk Sh*<br />

572K Sherlock<br />

284K Sherlock.i386<br />

<strong>Leopard</strong>:/Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong> scott$ mv Sherlock ~/Documents/<br />

<strong>Leopard</strong>:/Applications/Sherlock.app/Contents/<strong>Mac</strong><strong>OS</strong> scott$ mv Sherlock.i386 Sherlock<br />

NOTE The du command is a simple “disk usage” command. When used with the -hsk option,<br />

it will simply show you how big a file or directory is from the command line.<br />

Now I can run Sherlock to make sure everything works, and once I verify that it in fact does,<br />

I can run rm on the original Sherlock executable and gain back close to 300 KB of my precious<br />

disk space.<br />

NOTE What happens if something goes wrong? Well, that’s why we back up the original,<br />

which we can then just put back in place with no ill effect at all. By design, this should work<br />

without issue—however, as companies transition from PowerPC-only applications to universal<br />

applications, it’s prudent to expect that somewhere, somehow, it’s possible that something<br />

important could get lost in this process. It’s never happened to me, but it’s better to be safe<br />

than sorry.<br />

NOTE lipo is actually used to create and get information about universal binaries, not to<br />

break them apart. The use of lipo to thin out universal binaries is more of a useful side effect<br />

than an intention.<br />

Pipes, Redirection, and Background Tasks<br />

A few more things we should cover before we move on are the ability to pipe one command into<br />

another, the ability to redirect output (or input) to and from a command, and the ability to run<br />

tasks in the background. We’ve actually done each of these things in some of the preceding<br />

examples, yet as they are quite powerful tools, I’ll give a bit more depth here.

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

Saved successfully!

Ooh no, something went wrong!