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:

tty

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

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

node is an interactive JavaScript interpreter

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...

Directories

The Current Directory

Where am I?

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

To find out which directory you are in, type

pwd

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

Home Directory

Listing Directory Contents

Making a directory

mkdir code

Changing directories

Basic Command Review

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

Files

Text Editor

Source File

$ node hello.js
Hello, World!

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")
    • for Atom, use atom . ("atom 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

Also:

(image source: Clément Chastagnol

LAB: Next Steps

Want to learn enough command line to be dangerous? Check out https://www.learnenough.com/command-line-tutorial 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: http://overthewire.org/wargames/bandit/ 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 

Outline

[menu]

/