The command line
On a Mac, the command line is accessed through the Terminal app (in Windows, it's called Command Prompt.) You will find the Terminal app in the Applications/Utilities/
folder. When you launch it, a Terminal window will appear, like the one in Figure A-1:

Figure A-1. Terminal window
The prompt shows the name of the computer, a colon (:
), the current directory (the folder), a space, the current user, a dollar sign ($
), a space, and then the prompt symbol (□).
There are several hundred commands that you can run from the Terminal window. To see a list of them all, hold the Esc key down for a second and then press Y, to answer yes to the question. Each time the listing pauses, press the space bar to see the next screen of commands. Press Q to terminate the listing.
Press Ctrl+C to abort the execution of any Terminal command. Use the up and down arrow keys to scroll through the saved list of previously executed commands (to avoid re-typing them).
Try the cal
command (Figure A-2):

Figure A-2. The calendar command
It simply displays the calendar for the current month.
Most Terminal window commands are Unix commands. To view the Unix manual description (the man page) of a command, type man
followed by the command. For example, to see the man page for the calendar command, enter man
cal
.
Whenever a response is too large to fit in the window, use the space bar or the Q key to either continue to the next screen of output or to quit that output.
The prompt string is saved in a system variable name PS1
. You can change it to just about anything you want by a simple assignment statement. Here we changed it, first to "Now what?"
(just for fun), and then to "\w $"
. The code \w
means to specify the current working directory, representing the user's home directory with the tilde character (~
). The current working directory in Figure A-3 is the user's home directory.

Figure A-3. Changing the Command Prompt string
The part of the computer's operating system that responds to user commands this way is called the shell and a series of interactive commands and responses like these is called a shell session.
The shell session shown in Figure A-4 illustrates the cd
and ls
commands. The cd
command changes the current directory to the one specified in the command. So, cd
hub
changed the current directory from ~
(my home directory) to ~/hub
, which is a subdirectory of my home directory.

Figure A-4. Listing contents and changing directories
The ls
command lists the contents of the current directory. So, when I executed the ls
command the first time here, it listed the 11 subdirectories that I have in my ~/hub
directory. These included app
, books
, data
, and so on.
To go back up your directory tree, use the cd ..
command, or cd ../..
to go back up two levels at once. The double dot means the parent directory.