Entering Commands

Commands

Commands are verbs; they tell the computer to do something.

Entering a Command

Once you have Terminal open, you should see a string of characters that ends with a dollar sign. This is called the command prompt. A prompt looks something like this.

 walsh-9:~ bree$

Whenever you see a line in these slides prefixed with a $, that means that we’re typing something in at the prompt.

Executing a Command

In terminal, type in the name of the command, and press <ENTER>. Let’s trying using ls, a command to list files and directories

$ ls

Where Are You?

Note that when you’re at the prompt, you’re always running commands in the context of some location on your computer.

Let’s Repeat That: At the prompt, you’re running commands in the context of some location (think folder/directory) on your computer

What Was That Again?

Arguments

Arguments are the thing or things that a command acts on; they’re like nouns (or more formally, direct objects).

Commands and Arguments

Some commands can optionally have arguments:

Try this (list files in Desktop):

$ ls Desktop

Flags

Flags are like adverbs. They specify how a command is run.

(sometimes they’re also called options)

Commands and Flags

Commands can optionally have flags.

Try this (list all, including hidden, files in Desktop):→

$ ls -a Desktop

<TAB> Completion

You can use the <TAB> key to complete commands or file names. Try typing the following:→

The argument, Desktop, is automatically completed for you! Go ahead and run the command by pressing <ENTER> →

<TAB><TAB>

What if there are multiple matches? Type the letter l and then <TAB>. What happens? →

Nothing. Now try hitting <TAB> one more time. What happens? →

All of the possible commands that start with the letter l are shown.

Next and Previous Commands

You can use the <UP> or <DOWN> keys to go through previous and next commands. Try pressing <UP> twice, and <DOWN> once. What command is shown?

$ ls Desktop

Errors

Type the letter l and press <ENTER>.

$ l

What happens? →

-bash: l: command not found

More Errors

Type ls foo and press <ENTER>.

$ ls foo

What happens? →

ls: foo: No such file or directory

Activity: Drills!

Entering commands flash cards x 5 (use set 1)

We’ll do this together, then try downloading it yourself:

  1. Download drills.py to the home directory
  2. Type python drills.py
  3. When prompted for a number, enter 1
  4. CTRL-C quits

Lab

Entering Commands

Activity: Drills!

…And… again!

Entering commands flash cards x 5 (use set 1)

We’ll do this together, then try downloading it yourself:

  1. Download drills.py to the home directory
  2. Type python drills.py
  3. When prompted for a number, enter 1
  4. CTRL-C quits