Unix Cadillac Commands in OS X Yosemite

By Mark L. Chambers

Besides working with files and processes, the OS X command line has all kinds of sophisticated commands. For example, with the command line, you have instant access to a variety of tools for finding files or even stringing together commands.

Finding files in OS X

The command line gives you a number of ways to search for files on your hard drive. The most commonly used search command is find.

To use find, specify a starting point for the search followed by the name of the file or folder that you want to find. For example, to find the Fonts folder that belongs to your user, enter the command like this:

find ~/ -name "Fonts"

You should see at least one result of the find command.

/Users/markchambers/Library/Fonts

One great feature of the find command is that you can look for a file or folder in more than one location. Suppose you want to find a file named MyDocument that you know resides either in your Documents folder or on your Desktop. For this kind of search, use the find command like this:

find ~/Documents ~/Desktop -name "MyDocument"

In this example, you’re telling the find command which folders it should search when looking for the file named MyDocument.

Using pipes in OS X commands

Nearly all Unix commands can take on greater capabilities by using a construct called the pipe. A pipe is represented by that funny little vertical line ( | ) that shows up when you press Shift+. The pipe routes data from one command to another one that follows — for example, many Unix commands produce large amounts of information that can’t all fit on one page. (You might have noticed this behavior when you used the locate command.)

Joining two commands or functions together with the pipe command is piping. To tame the screens full of text, pipe the find function to the less command. The less command provides data one page at a time.

find ~/ -name "Fonts" | less

When the results fill up one page, the data stops and waits for you to press any key (except the Q key) to continue. When you reach the end of the results, press Q to quit and return to a command line prompt.