The Command Line

Shall we play a game?

from WarGames, (1983)

Historical Terminal

Computers used to not have screens! They looked like this:

tty

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

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" (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

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:

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? Start with this game: http://overthewire.org/wargames/bandit/ where you use your real command line ssh tool to connect to sandboxed hosts and infiltrate them.

Next Lesson   Previous Lesson

Outline

[menu]

/