Many Mac users avoid the command line altogether, a reasonable amount probably don’t even know it exists. For the curious out there, here are some basic and essential commands and functionalities to know if you want to get started using the Mac OS X Terminal. We’ll cover simple file manipulation, maneuvering in the file system, displaying and killing processes, and more. Remember to remove the brackets or the commands won’t work.
The Basics
ls -lalist all contents of a directory including hidden filescd [directory]move to the specified directory, cd /Applications will move to your applications foldermv [file1] [file2]mv is able to rename files or move them, depending on usagecp [file] [destination]copies a file to either a new filename or destinationcat [file] | moredisplay contents of a file screen by screen by ‘piping’ the contents through moretouch [file]creates a file with the given name, eg: touch test.txt will create a blank text filetopdisplay a continuously updated list of all running processes, including memory and cpu usage, PID is the process ID which you would use to kill a processps -auxlist all processes running from all users, -ux will list only processes of current userkill -9 [pid]kill the specified process id (basically force quit for the command line)rm [file]rm removes the specified file or directory, there is no warning so use with cautionping [ip]determine network latency by pinging another host
General Usability Tips
- Use the tab key, the tab key will autocomplete directories and filenames for you
- Enable colored terminal, this makes it easier to browse through large amounts of files
- If a command confuses you, try running it with the –help flag, which will often display basic instructions on the given command
- Remember manual pages exist on many commands as well, access them by typing
man [command], eg: man ping - If the output of a command flies by you and is too much to fit on one screen, try piping it through more, like so:
ls -la |morethis will enable you to see the output a screen at a time - You can export the contents of a file, output of a command, and results of a script to a text file using the alligators (improper terminology, excuse my forgetfulness), eg:
ls -la /Applications > applist.txt - If you’ve ever noticed your CPU load skyrocket inappropriately, a good place to find the errant process is with the
topcommand, use top in conjection withkillto find the process ID and kill the CPU hog - Don’t be afraid to get your hands dirty!
Filed under: Hosting, Leopard, OSX, Servers, Software | Tagged: -la, cd, command line, dir, ls, pid, terminal, unix

For all things Unix on Mac OS X you should also see Hyperjeff’s OS X page and resources such as codesnippets by joyent. Just my 2 cents!