The Command Line Junkie's Guide to Mac OS X

UPDATE 2007: This is old, incomplete and out of date. Disregard all content.

The Shell

Mac OS X ships with bash as the default shell as of version 10.3 "Panther". Older versions used the tcsh shell, but replacing it is simple enough. I won't go into details on how to configure the shell, since this subject is already covered adequately elsewhere.
I'm working on the assumption that you already know how to configure the bash shell, add aliases and commands in .profile and so forth. In this article I'll try to cover more Mac OS X-specific subjects.

Directory Structure

I recommend that anyone new to Mac OS X read the hier man page, which covers the functions of various unix root folders. The Mac OS X folder structure may seem confusing at first, but it is actually quite simple:

This folder contains all system-specific files from Apple. This includes frameworks, caches, components, extensions, plugins, preference panes and startup items. Third-party products should not go in here.

This folder contains all non-Apple-supplied system components, amongst them Perl, Python, Apache files, third-party startup items and application support files.

This is the user-specific Library folder, which is present in every user's home directory. It contains user-specific components and preferences.

Getting Information about the System

Apple ships some fine command line tools for getting information about your system:

sw_vers will print out the Mac OS X version and build number running.
system_profiler is essentially a CLI version of the System Profiler application.

The traditional UNIX tools are also available:

arch prints out the CPU architecture.
uname prints out operating system information

Working With Files

Mac OS X is a BSD-based operating system, with all the beauty that this entails. This means that the system ships with most, if not all of the most commonly used command line tools available in a standard *BSD installation. But Mac OS X is more than just another BSD -- it is packed with loads of Mac-specific stuff such as the HFS+ file system (and associated meta-data), resource forks and, of course, a state-of-the-art window environment.

You'll find that all the standard tools for working with files are present in Mac OS X.
df, ls, cd, cp, ln, du, rm are all there. However, these tools are generally not aware of heritage Apple technologies such as resource forks, Finder flags and file and creator types. The Apple Developer Tools do contain some Mac-specific command line utilities, located in /Developer/Tools. You may want to include these in your $PATH. I'll list the most interesting of these:

SetFile -- Edit HFS+ file meta-data
GetFileInfo -- View HFS+ meta-data of files
MvMac -- Resource-fork-aware version of mv
CpMac -- Resource-for-aware version of cp

While these tools cover some important aspects of working with file meta-data in the command line, they are not particularly comprehensive or UNIX-like. You may want to take a look at osxutils, my own GPL'd set of tools for working with Mac OS meta-data. It includes an ls-like utility called lsmac which lists HFS+ file meta-data.

Symlinks and Aliases

The Mac OS has its own heritage links/shortcut files which are called aliases. Aliases are fundamentally different from UNIX symbolic links since they don't point to a specific path; rather, the alias file references the file's file system reference number, which is independant from its actual location in the directory structure. This means that aliased files can be moved about without actually breaking the alias.

Unfortunately, aliases cannot be used via the command line. You cannot cd into an alias or edit it via the command line -- the actual data within the alias is stored in the resource fork. Apple has not provided any tool to create aliases via the command line, but I provide mkalias for this very task in my osxutils package (shameless plug).

Symbolic links work fine in the Mac OS X window environment -- the Finder displays and treats them just like aliases.

Updating and Installing

It's easy to maintain and keep Mac OS X up-to-date via the command line. The following tools are very helpful:

softwareupdate -- A simple command line tool to apply security patches and OS updates from Apple.
installer -- command line utility to install "packages" (.pkg), Apple's installer format.

Rebooting and Shutting Down

Although you can reboot or shut down Mac OS X systems via the traditional halt, reboot and shutdown commands, the Apple-recommended way of turning off the computer remotely is to send the Finder an Apple Event. This can be accomplished using the osascript command to run an AppleScript:

osascript -e 'tell application "Finder" to shut down'
osascript -e 'tell application "Finder" to restart'

Of course, this will only work if there's a user logged in, which will typically not be the case with, say, headless servers, in which case you should be able to use traditional UNIX commands without negative consequences.

Startup Items

Custom Mac OS X startup items should not be added to the rc boot scripts. Rather, you should create your own Apple Startup Items in /Library/StartupItems. The file format is simple enough -- basically a folder containing a script with the same name, plus an XML property list specifying the boot order and containing the strings to display in the Mac OS X boot panel. You can easily figure out the format by copying and modifying one of Apple's own Startup Items, a variety of which can be found in /System/Library/StartupItems. You may also want to take a look at a Mac OS X application called Armadillo which facilitates the creation and installation of Mac OS X Startup Items.

The Internet

Apple regrettably decided to replace the superior wget with curl. You can retrieve files from the Internet using curl -O [URL]. It is also possible to build lynx, the excellent text-only command line browser, or download a precompiled installer package.

Running MacOS X Applications

Apple uses a bundle format for Mac OS X applications. Every .app is in fact a structure of directories containing, amongst other things, the application binary and support files. There are two ways to go about running a .app application from the command line:

# open /path/to/

The open command tells the Finder to open the application in question, and is probably the most sensible way to run a Mac OS X app. However, this will only work if the Finder is running, which may not be the case with servers.

# /path/to/

This executes the binary within the application bundle directly, thus circumventing the need for the Finder. However, most Mac OS X applications will need a running window server session to function.


Mac OS X 10.3 "Panther" ships with the say command line program, which will speak the arguments passed to it using Apple's Speech Manager technology. You can set the voice to use via the -v flag. This can add extra flair to a shell script, or alternately serve as a very funny way to play tricks on co-workers whose machine you have SSH access to.

Important Links

Cool Stuff