Parts of a Computer

The Command Line

Shall we play a game?

from WarGames, (1983)

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.

When you type into the console and hit Enter you are pretending to type a line onto a TTY; the scrolling terminal is like a roll of printer paper.

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

Lab: Opening the Terminal

terminal next to browser

Lab: Interactive Calculator

  1. open a terminal
  2. look at the prompt -- it should end with a $ or > symbol
  3. type node -- that's you commanding the computer to launch node
  4. press the Return key (also called Enter)
  5. see the > prompt
  6. type 1 + 1
  7. press the Return key again
  8. see the 2

Node is a JavaScript Engine

Diagram: Node Train: Command Line

An "engine" is a type of program that either executes or empowers other programs.

NodeJS (aka node) is an engine that runs JavaScript programs -- either from files, or interactively from the command line.

A Tale of Two Prompts

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

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

When in doubt, try it out!

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

'pod' + 'cast'

If that doesn't print 'podcast', look at the prompt; you may be inside your shell instead of inside node.


Where am I?

Home Directory

WARNING: On some windows systems, Command Prompt will open to C:\Windows\System32. You can get back to your home directory by typing cd %HOME%

Listing Directory Contents

Lab: Home Decor

  1. Using your GUI desktop, navigate to your home directory and open it in a desktop window.
    (Your desktop is called "Finder" in MacOS, or "Explorer" in Windows)
  2. Using your terminal, list your home directory's contents.
  3. Look carefully at them both. What's the same? What's different?

Making a directory

mkdir code

Changing directories

Basic Command Review (Unix)

These apply to Mac / Unix / Linux / bash

Basic Command Review (DOS)

These apply to Windows / DOS / PowerShell

LAB: make a subdirectory and then enter it

  1. open Terminal or Command Prompt
  2. Confirm that you are in your home directory
  3. make a new subdirectory using mkdir code
  4. change into that directory using cd code
  5. make sure you're really there using pwd
    • On Windows use cd
  6. list its contents using ls (and note that it's empty)
    • On Windows use dir


Text Editor

Source File

$ node hello.js
Hello, World!

LAB: Hello, World

  1. Make sure you are in your code subdirectory using pwd or cd
  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)
    (If you are using VS Code, you can click Terminal → New Terminal for the built-in terminal panel)

  7. Run this file using node hello.js

What happens? Is this what you expected?

LAB: Countdown

  1. Inside your code directory, create a file named countdown.js
  2. Inside this file, put the following source code:

    let count = 10;
    while (count > 0) {
      console.log(count + '...');
      count = count - 1;
  3. Save the file

  4. In your terminal, run node countdown.js

Analyzing Countdown

Countdown Breakdown

Consider this a sneak peek; we will cover all of these concepts in later lessons

Command-Line Shortcuts

These work in bash:

bash shortcuts


(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

 Previous Lesson Next Lesson