UNIX Programs That Come in Handy (MacBook)

As a MacBook user, you might be surprised to know that many applications on your hard drive don’t reside in one of the typical Applications folders of Mac OS X. These applications, in fact, don’t have any graphical user interface like what you’re accustomed to. They’re accessible only from the command line. The remainder of this topic covers some of these applications.

Text editors

UNIX has many text-editing applications for use at the command line. Some of the more popular ones include pico, vi, and emacs. Each of these text editors has its pros and cons — and say thanks to the thorough folks at Apple, because all three are included with Snow Leopard! For my examples here, however, I use pico because it’s simple to use and sufficient for our needs.

Creating a new document

To create a text file by using pico, simply type pico at the command line. The result looks like Figure 1-7.
The pico program is a full-strength text editor, right from the command line.
Figure 1-7:
The pico program is a full-strength text editor, right from the command line.
This is the rough-and-tumble world of UNIX, which preceded the Macintosh by many years. Perhaps this will also help you to appreciate why the Macintosh was so revolutionary when it was introduced. (You can just hear the designers crowing, “We’ll call this a menu! Yeah, that’s the ticket!” The only graphics that you’d see on your monitor were the comics and sticky notes that you stuck to the bottom.)
At the bottom of the screen is a menu of common commands. Above the menu is a large, empty space where you can enter text, much the same as in the word processors that you already know and love. (For those of us that remember the halcyon character-based days of DOS, think older versions of Word and WordPerfect . . . or, if you’re a real computing dinosaur as I am, consider the original WordStar.) Type some text in that area. Anything will do . . . a letter to a friend, a grocery list, or your school homework.
When you’re finished entering your desired text, save the document with the WriteOut command in the pico menu. Directly next to each command in the pico menu is a keyboard sequence used to perform that command. (Refer to the bottom of Figure 1-7.) The # character is shorthand for the Control key on your keyboard. Thus, to save a file, press Control+O. This flies in the face of standard Mac keyboard conventions, where the letter O is traditionally used to mean Open.
After pressing the Control+O sequence, pico prompts you for a filename. Like most UNIX files, you’re permitted to enter a simple filename here or a full path to a file. For this example, save the file to your Documents folder, naming it MyPicoDocument.
After you’ve completed and saved the document, pressing Control+X will transport you away from Planet Pico and back to the command line.


Networking with the Terminal

Because UNIX isn’t a new phenomenon, it has many useful networking abilities built into it. In fact, UNIX was instrumental in creating much of what we now take for granted: e-mail, the Internet, and the World Wide Web. Thus, you’ll be happy to know that you can communicate over networks with the Terminal in practically any manner that you can dream of . . . and then some!

WWW and FTP

If you’ve used the Internet for any time, you’re probably familiar with the various means to transport data over a network. From FTP (short for File Transfer Protocol) and Telnet to e-mail and the Web, UNIX can handle it all. In fact, UNIX has a command for each of these functions (and many more that have passed into historical obscurity). Rather than use each individual command to send and retrieve data with the Terminal, Apple has conveniently provided a command that can handle them all: curl. The curl command is competent at all the standard network protocols. To see it in action, pass a Web address (or URL, to The Enlightened) to the curl command:
The result is that you see the HyperText Markup Language (HTML) page that’s located  Because this isn’t particularly useful for most people (it’s not very easy to read), you need to add the letter o as a flag. This specifies where you would like to save this file upon download. To save the HTML page to your Home directory, add the -o flag and a path to the destination file.
Don’t forget to precede all flags with a hyphen. For this example, it would be -o.
If you now perform an ls command, you see that curl has, in fact, downloaded the HTML and saved it to a file named mlctopics.html in your Home directory.
The beauty of curl is that it does much more than just retrieve Web pages: It’s equally comfortable with FTP transfers. FTP is used to download (or receive) files from a server as well as upload (or send) them. Like the previous HyperText Transfer Protocol (HTTP) examples, you only have to provide an FTP address in Uniform Resource Locator (URL) format, and curl will take care of the rest. Of course, most people want to save any files that they download via FTP — not view them in the Terminal as I did the HTML file. Therefore, as in the previous example, you should add the -o flag and a path to the destination of your download. This time, I download a README file about curl directly from the makers of curl.
curl -o -/Desktop/README.curl ftp://ftp.sunet.se/pub/www/ utilities/curl/README.curl
If you’re familiar with FTP, you might wonder whether curl can upload, too. Yes, indeed! Instead of using the -o flag, you need to use two flags: -T and -u. The -T flag denotes which file you want to upload. The -u flag denotes the username and password. Then, specify the FTP destination address of where you want to upload it. Because this example deals with an upload, the remainder of this example is for an imaginary FTP server. In real life, you’d use the appropriate FTP address, username, and password for an FTP server where you are allowed to upload.
curl -T /Desktop/README.curl -u username:passwd ftp://ftp.
yoursitehere.com /myfiles/README.curl
This example uploads the README.curl file from the Desktop folder that I downloaded earlier to an imaginary FTP server.
How do you spell success? C-u-r-l!
Sure, HTTP and FTP are handy, but did you know that there are many other protocols for network communications? One of the niftier ones is the Dictionary protocol. With it, you can look up words from any server that understands the protocol. Suppose, for example, that you want to know the meaning of the term DVD. Enter the following command to find out:
curl dict://dict.org/d:DVD
With curl, Dictionary, and your Dictionary Dashboard widget on the same MacBook, you might never use a “real” paper dictionary again!

Next post:

Previous post: