Apple

Navigating the Mac Shell

Erik Eckel explains the basics of the Mac Shell and goes over the basic commands that will help admins be more efficient.

Technology administrators and end users alike can better administer and more efficiently troubleshoot their Macs using the Terminal. The Terminal unlocks the power of the command line. Basic commands, meanwhile, enable accessing different directories and working with files. Before administrators and users unfamiliar with the Terminal application and command line can become proficient, they must understand the role the Mac Shell plays and methods for entering commands, leveraging command options, recalling previous commands, and even managing Shell jobs.

The Mac Shell

When a user opens the Mac Terminal (found within the Applications folder's Utilities subfolder), the Mac Terminal application opens. The Terminal is not the Shell. The two are altogether different. The Terminal is the application that displays a Shell window or windows. The Shell is the actual command line interface the user leverages to enter commands directly into OS X.

By default, a single Shell window appears when an operator opens the Terminal application. As previously described, the Shell actually reads and interprets commands and prints (or displays) a command's output.

To open a second Shell in a second Terminal window, with Terminal open, users need only to press the Command and N keys simultaneously. The key combination triggers a shortcut combination that opens a second Terminal window. If, however, the operator wishes to open a second Shell within the same Terminal window, the operator can do so by pressing the Command and T key combination. Each resulting Shell window is capable of separately receiving, interpreting, and displaying commands.

Leveraging command options

Commands, or the text strings users enter at the OS X Shell prompt, are sometimes simple and straightforward. Typically, users add additional parameters to a command to fine tune results. The additional parameters are known as options. Often a command option is followed by an argument, interface, or an additional piece of information unique to the task at hand.

For example, if a user wishes to check the network settings assigned to his or her workstation, the user can type ifconfig at the Shell prompt. The command, once executed, returns quite a bit of information, including the MAC address and LAN IP addresses assigned to each network interface. If the same user wished to check the network address for just his or her Mac's wireless network interface, the user would type ifconfig en1, as en1 specifies the interface the command should check.

Here's a second example. Say a user needs to test network connectivity to the local network's router. The user could enter ping 10.0.0.1, assuming the local network router's address is 10.0.0.1. Ping, in this example, is the command. The 10.0.0.1 string, meanwhile, is the unique piece of information, or host address, the user supplies. But say the user wishes to add an option to the command. Instead of pinging the router an unspecified number of times, the user could specifically instruct the ping command to try pinging the router just two times. The subsequent command, using the -c option, would look like this: ping -c 2 10.0.0.1.

Recalling previous commands

Typically, and especially when troubleshooting, administrators make minor changes and test the results of a change by running the same command again or making minor modifications to a previously run command. Simply pressing the up and down arrow when the cursor is positioned at the Shell prompt prompts the Shell to display the previously entered commands in the order they were last entered. This simple shortcut saves a tremendous amount of time when having to repeatedly enter the same commands or make minor adjustments to what can become complex strings of text and numerals.

Managing Shell jobs

Occasionally a Shell command takes too long to complete or keeps running, such as a ping test that does not specify a -c option to limit the number of ping attempts. Administrators and users can terminate a command by pressing the Control and C keys simultaneously.

Pressing the Control and D keys simultaneously terminates shell sessions. Alternatively, users can type exit, followed by Enter, at the Shell prompt.

Shell sessions that are abruptly terminated using the kill command may not function properly following the interruption. Users can often return the Shell to normal operation using the Control and J shortcut key combination.

About

Erik Eckel owns and operates two technology companies. As a managing partner with Louisville Geek, he works daily as an IT consultant to assist small businesses in overcoming technology challenges and maximizing IT investments. He is also president o...

4 comments
C-3PO
C-3PO

I don't really want to start a windows/mac war here, but I find it ironic that this article makes this sound like such a wonderful hidden feature! I think it is telling of the way MAC was built and the audience to which it speaks. The command window in MS Windows and the Terminal in Linux are both rather well known by users, and although the general user may not use them much (if at all), nobody is surprised when you go to open one up... yet, surprise surprise, there is a similar window on MAC...

dbucciar
dbucciar

I've only looked at the Mac Shell once or twice, but I recall noticing that it's a standard bash (Bourne-Again SHell) interface. There are tons of on-line references for bash, as well as a few good books out there. I believe the O'Reilly Nutshell book on bash is pretty good.

rupniksc
rupniksc

I think one of the most useful tools in the shell environment is the command "man" which is short for manual. I also use the "-k term" option which is a search of "term" in the manuals. So "man ls" will return the manual page for the "ls" command.

Adam S
Adam S

Thank you for continuing this series. I'm familiar with most of the basics from my scant interaction with Linux. I didn't know about the Ctrl-J. How is it technically more aggressive than Ctrl-C? I look forward to learning some OSX-specific shell tips and tricks in the future.

Editor's Picks