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.