From Zero to AI

Lesson 2.1: Why Do We Need the Terminal

Duration: 45 minutes

Learning Objectives

After completing this lesson, you will be able to:

  • Explain what the command line is and how it differs from graphical interfaces
  • List reasons why developers prefer the terminal for many tasks
  • Open the terminal on your operating system
  • Execute your first commands

Introduction

You've been using your computer through a Graphical User Interface (GUI) your whole life. You click icons, drag files, and interact with windows. But there's another way to interact with your computer: by typing commands. This is called the Command Line Interface (CLI), and it's how programmers worked with computers long before mice and icons existed.

Don't worry if it feels strange at first. By the end of this module, you'll understand why so many developers prefer typing commands over clicking buttons.


Main Content

What is the Command Line?

The command line is a text-based interface where you type commands to tell your computer what to do. Instead of double-clicking a folder to open it, you type cd folder-name. Instead of right-clicking to create a new folder, you type mkdir new-folder.

Different names, same thing:

Term What It Means
Command Line The text-based interface itself
Terminal The application that provides access to the command line
Console Another name for terminal
Shell The program that interprets your commands (bash, zsh, PowerShell)
CLI Command Line Interface (as opposed to GUI)

GUI vs CLI: A Visual Comparison

GUI (Graphical User Interface)         CLI (Command Line Interface)
================================       ================================

 ┌──────────────────────────┐          ┌──────────────────────────┐
 │  [Folder] [Folder] [File]│          │ $ ls                     │
 │                          │          │ Documents  Downloads     │
 │  [File]   [Folder] [File]│          │ Pictures   projects      │
 │                          │          │                          │
 │       Double-click       │          │ $ cd projects            │
 │       to navigate        │          │ $ ls                     │
 │                          │          │ website  app  notes      │
 │       Drag to move       │          │                          │
 │                          │          │ $ mkdir new-project      │
 │    Right-click menus     │          │ $ _                      │
 └──────────────────────────┘          └──────────────────────────┘

      Point and Click                       Type and Enter

Why Developers Love the Terminal

1. Speed

Once you know the commands, typing is faster than clicking through menus.

Creating 5 folders in GUI:

  1. Right-click
  2. Select "New Folder"
  3. Type name
  4. Repeat 4 more times

Creating 5 folders in CLI:

mkdir folder1 folder2 folder3 folder4 folder5

One command, done.

2. Automation

You can save commands in a file (called a script) and run them again whenever you need. Imagine setting up a new project with dozens of files and folders with a single command.

# This script creates a complete project structure
mkdir src tests docs
touch src/index.ts src/utils.ts
touch tests/index.test.ts
echo "# My Project" > README.md

3. Power

Some things can only be done from the command line. Most programming tools (like Node.js, Git, npm) are designed to be used from the terminal.

# Install project dependencies
npm install

# Start a development server
npm run dev

# Commit code changes
git commit -m "Add new feature"

4. Remote Access

When you work with servers (computers in the cloud), there's usually no graphical interface. The only way to interact with them is through the command line.

5. Precision

The command line forces you to be explicit about what you want. This prevents accidental clicks and makes your actions reproducible.

The Terminal Application

Let's find and open your terminal:

macOS

Option 1: Spotlight

  1. Press Cmd + Space
  2. Type "Terminal"
  3. Press Enter

Option 2: Applications

  1. Open Finder
  2. Go to Applications > Utilities
  3. Double-click Terminal

Pro Tip: Many developers on Mac use iTerm2 as a more powerful alternative.

Windows

Option 1: Windows Terminal (Recommended)

  1. Press Win key
  2. Type "Terminal" or "Windows Terminal"
  3. Press Enter

Option 2: PowerShell

  1. Press Win key
  2. Type "PowerShell"
  3. Press Enter

Option 3: Git Bash (if installed)

  • Comes with Git for Windows
  • Provides Unix-like commands on Windows

Note: Windows has two main shells: Command Prompt (cmd) and PowerShell. We recommend PowerShell or Windows Terminal as they're more modern. If you install Git for Windows, you also get Git Bash, which uses the same commands as Mac/Linux.

Linux

Option 1: Keyboard shortcut

  • Press Ctrl + Alt + T

Option 2: Applications menu

  • Look for "Terminal" in your applications

Anatomy of the Terminal

When you open the terminal, you'll see something like this:

┌─────────────────────────────────────────────────────────────────┐
│                                                                 │
│  username@computer-name:~$                                      │
│  ▲         ▲            ▲ ▲                                     │
│  │         │            │ │                                     │
│  │         │            │ └── Prompt (waiting for your command) │
│  │         │            │                                       │
│  │         │            └──── Current directory (~ = home)      │
│  │         │                                                    │
│  │         └─────────────── Computer name                       │
│  │                                                              │
│  └───────────────────────── Your username                       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

The exact format varies by system:

  • macOS (zsh): username@MacBook ~ %
  • Linux (bash): username@hostname:~$
  • Windows (PowerShell): PS C:\Users\Username>

The important part is the prompt ($ or % or >) which tells you the terminal is ready for your command.

Your First Commands

Let's try some basic commands. Type each one and press Enter:

1. Who am I?

whoami

This prints your username. Simple, but it confirms the terminal is working!

2. Where am I?

pwd

Print Working Directory. This shows your current location in the file system.

3. What's here?

ls

List. This shows all files and folders in your current location.

4. What's today?

date

Displays the current date and time.

5. Clear the screen

clear

Clears all the text, giving you a fresh terminal. (Keyboard shortcut: Ctrl + L)

Understanding Command Structure

Commands follow a pattern:

command [options] [arguments]
  • command — What you want to do (e.g., ls, cd, mkdir)
  • options — Modify the command's behavior (usually start with -)
  • arguments — What you want the command to act on

Examples:

ls                    # Just the command
ls -l                 # Command with option (long format)
ls Documents          # Command with argument (specific folder)
ls -la Documents      # Command with options and argument

Common Mistakes (and How to Fix Them)

Problem Solution
command not found Check spelling, commands are case-sensitive
Nothing happens Command succeeded silently (many commands don't print anything on success)
Permission denied You might need admin rights (we'll cover this later)
Stuck in a command Press Ctrl + C to cancel
Terminal is frozen Press Ctrl + Q or close and reopen

Practice Exercise

Task

Open your terminal and complete these tasks:

  1. Run whoami and note your username
  2. Run pwd and note your current directory
  3. Run ls to see what's in your current directory
  4. Run date to see the current date
  5. Run clear to clear the screen
  6. Try running ls -la and compare the output to just ls

Questions

After completing the exercise, answer these questions:

  1. What is your home directory path?
  2. How many items did ls show vs ls -la? Why might they differ?
  3. What does the -l option seem to do? What about -a?
Hint for Question 2

The -a option shows "all" files, including hidden ones (files starting with a dot like .bashrc or .gitconfig).

Hint for Question 3
  • -l means "long format" - shows details like permissions, size, and date
  • -a means "all" - includes hidden files
  • -la combines both options

Key Takeaways

  • The command line is a text-based way to interact with your computer
  • Terminal is the application, shell is the program interpreting commands
  • Developers prefer CLI for speed, automation, power, and remote access
  • Commands follow the pattern: command [options] [arguments]
  • Essential first commands: whoami, pwd, ls, date, clear
  • Press Ctrl + C to cancel a command if you get stuck

Resources

Resource Type Difficulty
The Command Line - MDN Documentation Beginner
Command Line for Beginners - freeCodeCamp Tutorial Beginner
Terminus - Command Line Game Interactive Game Beginner