Operating systems

Go under your Mac's hood with the OS X Terminal

Apple's Mac OS X has a powerful command-line interface that many users will never even know exists. It's not for everyone, but for techs the Terminal can be a powerful tool. If you haven't explored the command-line resources provided with OS X, here's where to begin.

Apple's Mac OS X has a powerful command-line interface that many users will never even know exists. It's not for everyone, but for techs, the Terminal can be a powerful tool. If you haven't explored the command-line resources provided with OS X, here's where to begin.

-------------------------------------------------------------------------------------------------------------------

Modern operating systems work really hard to impress us with their graphical refinements. Doing so makes good marketing sense, certainly. Eye candy pulls in those folks browsing in the retail sales aisles, and pretty screenshots grab attention online. Graphical user interfaces aren't a necessity for working with personal computers, though. Command-line interfaces are where operating systems began, and they're still a tool that power users can turn to when they need to get something done with a minimum of fuss.

Apple's Mac OS X is built on top of a Unix-based operating system called BSD, and like Unix, OS X has its own command line. Terminal, the program that launches the command-line interface on a Mac, can be found in the Utilities folder within a system's Applications directory. Upon launching Terminal, one is confronted with a white window, empty except for a command prompt.

"Why bother with a Mac's command line?" some may ask. If you're used to supporting Macs via their graphical interface, Terminal will come with a bit of a learning curve, but sometimes it's the only way to accomplish a particular task. For example, many a Mac user has been confronted with items that can't be emptied from the system's Trash by normal means. In my experience, this often results from problems with a file's ownership or permissions properties, and a quick way to clean up these files is by launching the Terminal and using sudo and rm to delete the offending items via the command line.

(For those who want to try the previous trick themselves, bear in mind that OS X has several system directories where trashed files are stored until they're deleted. To make sure you know where your culprits are stuck, find out their system path using the GUI's Get Info command.)

OS X uses common open-source command sets within Terminal. Recent builds since version 10.3 "Panther" provide the bash shell for the command line, and earlier versions use tcsh; a web search will turn up any number of references for these command shells that will work fine with Mac OS X. If you'd like more Mac-specific documentation--probably the best place to start for anyone who hasn't used a Unix-like command line before -- TechRepublic has a couple of chapters available from O'Reilly's Mac OS X reference volumes:

Once you're comfortable with the basics of a Unix-like command shell as used by the Terminal, you should look into the Mac-specific command-line utilities that Apple has developed. Since Mac OS has a built-in Secure Shell server, a skilled tech can accomplish almost any maintenance or support task on a remote Mac without having to worry about being restricted to Apple's GUI tools. You can find Apple's guide to the command line for System Administrators here:

Graphical interfaces make computers more accessible for casual users, but for those in the know, the command line is where the real power lies. If you're supporting Macs, I think a familiarity with the power of the Terminal is something worth adding to your repertoire.

A word to the wise, though: it's possible that through careless use of command-line tools, one could do a lot of damage to a system. Always make backups.

5 comments
bob
bob

I firmly believe that a person supporting the Mac community must know the system behind the GUI. Since the Mac is a "Linux" based system, most of the general Linux commands work just fine here and are able to create or fix problems. I find that using the Terminal from remote is ideal to fix a lot of problems and also to be able to check various logs and other items that are too visually intense and slow over a tcp connection. I use a VNC connection most of the time to check on a Mac (mostly iMacs) and I may open the terminal from that connection to check on problems and maybe even copy/move files or set permissions between users that is not very easy under the GUI. Open the terminal and have some fun, but be sure you backed up the system before you "tweak" things. There are a lot of tricks in the terminal and it is very powerful, so be careful

adrian
adrian

just a small correction; the Mac is not a linux based system it is BSD based.

williamjones
williamjones

Thanks for your thoughts, bob. I've used VNC with the Macs that I support (Chicken of the VNC is a great freeware VNC client for the Mac, if anyone's looking for one). Apple also has a network system management tool that's very similar to VNC, called Remote Desktop. Where some knowledge of command line utilities really shows value is the fact that an admin can turn on OS X's built-in SSH server and allow remote shell logins, and use the command-line to service a machine from anywhere. Graphical remote management tools are "easier" to use, but an SSH shell requires virtually no bandwidth. That makes it great for servicing a machine that may be off somewhere where the pipes are narrow. One thing that SSH has over VNC, as well, is that the default VNC implementation doesn't use any encryption (though I've seen some proprietary versions that do). You shouldn't send any passwords over an unencrypted VNC connection, though it's not too difficult to use SSH port forwarding to run VNC over an SSH tunnel. Here are some instructions on how to do that from MacTech. Thanks for your feedback!

josejperez1964
josejperez1964

BSD does stand for Berkley Software Distribution. There are several BSD variants in existence today (Mac OS X being one). However, Mac OS X is not a Linux variant since it does not use the Linux kernel and is based on NeXtStep. Its kernel is built on the XNU kernel (see Wikipedia link below). However, BSD is considered a branch of UNIX since it used the same initial code base of AT&T UNIX at its start. Hence Apple's description of Mac OS X as being UNIX based is correct. See links below. http://en.wikipedia.org/wiki/Berkeley_Software_Distribution http://www.bsd.org