Handy Unix Programs in OS X Yosemite - dummies

Handy Unix Programs in OS X Yosemite

By Mark L. Chambers

As a Macintosh 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 OS X. These applications don’t have a GUI like what you’re accustomed to. They’re accessible only from the command line.

Text editors

Unix has many text-editing applications for use at the command line. Some of the more popular ones include nano, 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 Yosemite!

Creating a new document in nano

To create a text file in nano, simply type nano at the command line.

A blank document in Nano.

This is the rough-and-tumble world of Unix, which preceded the Macintosh by many years. Perhaps this also helps you appreciate why the Macintosh was so revolutionary when it was introduced.

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 the word processors you already know and love. (For those who remember the halcyon character-based days of DOS, think older versions of Word and WordPerfect — or, if you’re a real computing dinosaur, 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.

After you finish entering your desired text, save the document with the WriteOut command in the nano menu. Directly next to each command in the nano menu is a keyboard sequence used to perform that command. (Refer to the bottom of the figure.)

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, nano prompts you for a filename. As with 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 MyNanoDocument.

After you complete and save the document, press Control+X to transport you away from Planet Nano and back to the command line.

Networking with the Terminal

Because Unix isn’t a new phenomenon, it has many useful networking capabilities built in to it. Unix was instrumental in creating much of what we now take for granted: email, 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!


If you’ve used the Internet for any time, you’re probably familiar with the various means to transport data over a network. From File Transfer Protocol (FTP) and Telnet to email and the web, Unix can handle it all. 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:

curl http://www.mlcbooks.com

You see the HyperText Markup Language (HTML) page. 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.

curl -o ~/mlcbooks.html http://www.mlcbooks.com

Don’t forget to precede all flags with a hyphen.

If you now perform an ls command, you see that curl downloaded the HTML and saved it to a file named mlcbooks.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 (receive) files from a server as well as upload (send) them. Like the previous HyperText Transfer Protocol (HTTP) examples, you only have to provide an FTP address in Universal Resource Locator (URL) format, and curl takes care of the rest.

Of course, most people want to save any files they download via FTP — not view them in the Terminal. Therefore, you should add the -o flag and a path to the destination of your download. This time, download a README file about curl directly from the makers of curl. (Note: Most FTP servers require a valid user ID and password before you’re allowed to download.)

curl -o ~/Desktop/README.curl ftp://ftp.sunet.se/pub/www/utilities/curl/README.curl

If you’re familiar with FTP, you might be wondering 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

This example uploads the README.curl file from the Desktop folder.