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.

306<br />

CHAPTER 18 INTRODUCING DARWIN AND THE SHELL<br />

<strong>Leopard</strong>:~ scott$ find ~/Documents/Shakes*<br />

/Users/scott/Documents/Shakespeare<br />

/Users/scott/Documents/Shakespeare/macbeth<br />

/Users/scott/Documents/Shakespeare/macbeth/soliloquy4<br />

/Users/scott/Documents/Shakespeare/nothing<br />

/Users/scott/Documents/Shakespeare/tomorrow<br />

Listing directories is nothing new, but find becomes very useful with its ability to search for<br />

matches of specific file properties, the most popular being the name of the file. To use find this<br />

way, we give find the directory we wish to traverse, and then enter the -name option, followed by<br />

our search string. For example, if we were looking for our soliloquy in our Documents folder, we<br />

could use the following:<br />

<strong>Leopard</strong>:~ scott$ find ~/Documents -name "sol*"<br />

/Users/scott/Documents/Shakespeare/macbeth/soliloquy4<br />

Other properties that you can use as search parameters for find include the file’s owner and<br />

its group.<br />

NOTE When using find, it’s best to have a good general idea of the location of the file you<br />

are looking for. While it’s perfectly acceptable to do something like find / -name "sol*", find<br />

is not a fast command, so in addition to getting a number of false hits and warnings (mostly<br />

Permission Denied warnings from subdirectories that find isn’t allowed to look in), it would<br />

take a relatively long time to perform such a search.<br />

Unlike find, whereis is tailored specifically for finding executable files. It does this by specifically<br />

searching the common places where programs live (primarily the various bin and sbin<br />

directories for a specific program name you enter). For example, if you wanted to see where the<br />

whereis command is located, you could do this:<br />

<strong>Leopard</strong>:~ scott$ whereis whereis<br />

/usr/bin/whereis<br />

While this may seem trivial on a certain level, there are a couple of good reasons to use this.<br />

First, if you occasionally compile or install your own Darwin software (which we’ll talk about in<br />

the next chapter), at some point you may end up with two copies of the same program, and<br />

whereis will help you find them so you can deal with it. Second, scripts written in languages like<br />

Perl, Python, or Ruby often want to know where the language executable is, and whereis is a<br />

quick way to determine that.<br />

lipo<br />

NOTE Two other commands worth mentioning here are locate and mdfind. locate searches<br />

its database for matches to your query, which makes it quite a bit faster than find—however,<br />

it’s possible that what you are looking for isn’t in the database. mdfind is a command unique to<br />

<strong>Mac</strong> <strong>OS</strong> X that actually searches on Spotlight’s metadata. This makes it very fast and powerful—<br />

however, there is one minor setback in that Spotlight doesn’t always index items until they are<br />

opened in the Finder. So, for example, our soliloquy4 text file may not show up in an mdfind<br />

search (or Spotlight search), at least until it is accessed by a non-Darwin application. As such,<br />

mdfind wouldn’t be a first choice for looking for something in the Darwin file system on the<br />

whole (however, it’s an excellent choice if what you are looking for is visible in the Finder).<br />

lipo is a command that has special meaning to <strong>Mac</strong> <strong>OS</strong> X universal binaries. When Apple<br />

switched hardware platforms from the PowerPC architecture to the Intel architecture, they introduced<br />

the universal binary, which allows the application to run natively on both platforms.<br />

Whether you are running an older PowerPC <strong>Mac</strong> or a newer Intel <strong>Mac</strong>, you probably don’t need

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

Saved successfully!

Ooh no, something went wrong!