Terminal

Access the Mac command line by starting Terminal, which you can find in your list of applications. Once started, you can create new Terminal windows with CMD+N, or a new tab with CMD+T. Close a tab or window with CMD+W.

Command Prompt

When you first open the Terminal, you might see something like:

AlicesMac:~ alice$

This is called the command prompt. You'll see a blinking vertical line, called the cursor. This shows where the characters you type will appear, and also let you know the prompt is ready to receive input (if a program is running, you won't see it).

The prompt also gives you some useful information. Here, we can see that we're on a computer called AlicesMac, we're in the ~ (home) directory, and username is alice.

Have a look at your command prompt now and see if you can extract these details from your own prompt.

At the command prompt, you type (or paste in) a command which runs when you press ENTER.

Running programs, specifying options

Normally at the terminal you run programs or scripts which do something for you. For example, to count the number of words in a file. Because programs often need some kind of input (such as a name of a file or directory to process) we have to provide parameters (or arguments or options).

It's typical that this essential parameter - the thing you want the program to work with - is typed after the name of the program. So to use the program wc to show the number of words in the file 'essay.txt', we could try something like the following:

AlicesMac:~ alice$ wc essay.txt
       1       2      10 essay.txt

All we really wanted to do is find out the number of words, so let's find out if we can narrow down wc's output. To do so, we need to turn to the documentation. OS X has in-built man pages (manual pages) that are useful for getting quick information on a command. Just give man the name of the command you're interested in:

man wc

Running this, we get pages of information about the wc command (shown here excerpted):

SYNOPSIS
     wc [-clmw] [file ...]
    ...
     The following options are available:
      -w   The number of words in each input file is written to the standard output.
    ...
    When an option is specified, wc only reports the information requested by that option.

The man page gives us some clues as the options we can provide it, and how we use them. -w looks useful, so we can try that, putting it before the filename as the manpage shows us:

AlicesMac:~ alice$ wc -w essay.txt
       2 essay.txt

Now the result is more succinct: essay.txt has two words in it. (time to get cracking!)