Putting It Together

The Unix syntax and vocabulary presented in this chapter is all well and good, and it’ll give you the rosy glow of having mastered something new. But it still doesn’t entirely explain why Unix gives programmers sweaty palms and dilated pupils.

The real power of Unix comes down the road—when you start stringing these commands together.

Suppose, for example, you want to round up all the TIFF image files related to your Yosemite project, scale them to a common size, convert them to JPEG files, and copy them to an FTP site. How would you go about it?

You could, of course, use Spotlight to search for all TIFF files that have “Yosemite” in their names. But what if your images were named otherwise but kept in folders with Yosemite in their names? You would have to find those folders first, and then the TIFF files within them.

You could perform the next step (scaling and converting the image) either manually or by a preprogrammed script or Automator workflow, using a program like Photoshop or even iPhoto. Once the images were all done, you’d need to collect them and then use your favorite FTP program to upload them to the server.

If you’ve mastered Unix, though, you could shave 12 minutes off of your workday just by changing to an empty working directory (in this example, ~/Stage) and typing this as one long line:

find ~ -type f -ipath '*yosemite*tif' -print0 | xargs -0 sips -Z 250 -s format jpeg --out ~/Stage && echo "put -r /Users/chris/ Stage/* /Incoming/" | sftp chris@coast-photo.com ...

Get Mac OS X Lion: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.