The Command Line

  • the TERMINAL is a window into which you can talk directly to your computer
    • aka console or command line or command prompt or shell

Shall we play a game?

from WarGames, (1983)

  • when you type into the terminal, you are issuing COMMANDS to the computer
  • a CLI (Command Line Interface) is different from the GUI (Graphical User Interface) you are used to
    • more primitive
    • more powerful

Historical Terminal

Computers used to not have screens! They were connected to devices like this:


the Terminal app is a direct descendant of a TeleType printer or TTY.

See this twitter thread for more history and TTY pix.

picture of Teletype Corporation ASR-33 on display at the Computer History Museum by ArnoldReinhold [CC BY-SA 3.0] via Wikimedia

Opening the Terminal

  • to open your Terminal:
    • Mac OS: launch the "Terminal" application
    • Windows: launch the "Cmdr" application (pronounced "Commander") and select "git bash" [TODO: verify on windows]
  • Important: make your terminal as tall as possible
    • when reading a program's output you want to start reading at the top...
    • ...and if your window is too short then the top lines will scroll away and you will miss them
    • Make it look like this:

terminal next to browser

Lab: Interactive Calculator

  1. open a terminal
  2. type node -- that's you commanding the computer to launch node
  3. press the Return key (also called Enter)
  4. see the > prompt
  5. type 1 + 1
  6. press the return key again
  7. see the 2
  • Yay! Your computer is an expensive calculator!
  • Bonus: what other math can you do?

node is an interactive JavaScript interpreter

  • From now on, whenever you see text in the code font, try typing it into the terminal and see what happens!

A Tale of Two Prompts

WARNING: Before you start typing, look at the prompt!

  • the shell is the command line that the terminal starts with
    • its prompt is usually $ (Mac / Linux) or C:\Users\alice> (Windows)
  • node is a command line that is launched from the shell
    • its prompt is usually >

From inside node, if you want to get back to the shell...

  • type CONTROL-C twice
  • or type .exit and Enter


  • a DIRECTORY is a location on your hard disk
    • also called a FOLDER
  • directories can contain FILES
  • directories can also contain other directories (called SUBDIRECTORIES)

The Current Directory

  • inside the Terminal, you are always inside a directory
  • it is very important not to get lost! You must try to remember which directory you are in.

Where am I?

It is very easy to get lost in a maze of directories.

To find out which directory you are in, type


This stands for "print working directory" or "present working directory" (not "password").

Home Directory

  • when you first open the Terminal you are in your HOME DIRECTORY
  • usually you don't want to store files directly in here
  • for this class, we recommend:
    • create a code directory inside your home directory
    • create a new directory inside code for each lesson or project

Listing Directory Contents

  • when you type ls ("list") it shows the contents of the current directory

    • On Windows you might need to type dir instead
  • if you type ls -al ("list all long") it also shows hidden files and extra info like the modification date

Making a directory

  • when you type mkdir ("make directory") it creates a new SUBDIRECTORY inside the current directory
mkdir code

Changing directories

  • cd ("change dir") moves you into a different directory
  • For example, cd code would move you into a subdirectory named code
  • If you ever get lost, type cd all on its own and press the return key. This will send you back to your home directory.
    • (unix shell only, not Windows)

Basic Command Review

  • pwd ("print working dir") -- shows the name of the current directory
  • ls ("list") -- shows the contents of the current directory
  • mkdir ("make dir") -- creates a new SUBDIRECTORY inside the current directory
  • cd ("change dir") -- move into a different directory

These apply to Mac & Unix shells, but most work in Windows too

LAB: make a subdirectory and then enter it

  1. open Terminal
  2. make a new subdirectory using mkdir code
  3. change into that directory using cd code
  4. make sure you're really there using pwd
  5. list its contents using ls (and note that it's empty)
    • On Windows you might need to type dir instead of ls


  • a file is a place on disk for storing stuff
  • "stuff" here could be anything at all
    • documents, pictures, sounds, applications...
  • every file lives inside a directory

Text Editor

  • a text editor is a program that edits a text file
  • a text editor is like a word processor
  • but a text editor is not a word processor
  • You probably have VS Code
    • others include TextMate, Notepad++, Sublime Text, Vim, Emacs, Atom
    • but NOT TextEdit or Notepad or Microsoft Word

Source File

  • source code is the essence of a program
  • source files are text files that contain source code
  • to RUN a JavaScript program you type node and then the name of the source file
$ node hello.js
Hello, World!
  • The Recipe Metaphor
    • source file ≈ recipe
    • running a program ≈ cooking

LAB: Hello, World

  1. Make sure you are in your code subdirectory using pwd
  2. Open this directory in your text editor
    • for VSCode, use code . ("code dot")
  3. Create a file named hello.js using the File > New menu
  4. Inside this file, put the following source code:

    console.log("Hello, World!");
  5. Save the file

  6. Switch back to the terminal (using Alt-Tab or Cmd-Tab or clicking)

  7. Run this file using node hello.js

What happens? Is this what you expected?

Command-Line Shortcuts

These work in bash:

bash shortcuts


  • use Esc instead of Alt for the above
  • Esc-Backspace (delete previous word)
  • up/down arrow (scroll through history)
  • End and Home (jump to end or beginning of line)
  • Tab for auto-completion of filenames (e.g. typing node hTab will emit node hello.js)

(image source: Clément Chastagnol

LAB: Next Steps

Want to learn enough command line to be dangerous? Check out by Michael Hartl (founder of Tau Day and all around solid geek).

Want to be a command-line hacker like in War Games? Play this game: where you use your real command line ssh tool to connect to sandboxed hosts and infiltrate them.

Want to learn the history of software user interfaces and operating systems? Read In The Beginning Was The Command Line by Neal Stephenson