1 WEB FOUNDATIONS

The Terminal: Cross-Platform CLI Mastery

πŸ’» Mastering the Terminal (Windows, Mac, Linux)

🎯 Lesson Objectives

By the end of this lesson, learners will be able to:

  • Understand what the terminal is and how it differs across platforms.
  • Navigate directories using standard commands.
  • Create, view, copy, move, rename, and delete files and folders using the CLI.

⌨️ What is the Terminal?

The terminal (also called the command line) allows you to interact with your computer using text commands instead of a mouse.

Developers use the terminal to:

  • Manage files and folders efficiently.
  • Run programs and automated scripts.
  • Use version control (Git).
  • Control development servers and tools.

πŸ›‘οΈ One Language, Many Platforms

In modern software engineering, the Terminal is the universal language. However, how you access it depends on your operating system:

  • Mac Users: macOS is built on a Unix foundation; your native Terminal app supports these commands natively.
  • Linux Users: This is your natural environment.
  • Windows Users: This is critical. Standard Windows tools like "Command Prompt" (CMD) or "PowerShell" follow different rules. To run these standard developer commands on Windows, you must use a compatibility tool like Git Bash or the Windows Subsystem for Linux (WSL).

πŸ“‚ Understanding Directories

A directory is simply another name for a folder. The terminal lets you move between directories and manage what’s inside them.

The Shell Prompt

Every line starts with a prompt, giving you context: dev@machine:~/projects$

  • dev: The current user.
  • ~: Shortcut for your Home Directory.
  • $: Indicates you are a standard user.

πŸ”‘ Essential Commands

πŸ“ pwd β€” Print Working Directory

Shows the folder you are currently inside.

pwd

πŸ“„ ls β€” List Files and Folders

Shows the contents of the current directory.

ls

Useful Flags

  • ls -a: Shows hidden files (files starting with a .).
  • ls -l: Shows a detailed list (size, date, permissions).
  • ls -la: Combines bothβ€”shows hidden files in a detailed view.

πŸ“ cd β€” Change Directory

  • Move into a folder: cd projects
  • Move back one level: cd ..
  • Go to home directory: cd ~

🧹 clear β€” Clear the Screen

Removes previous commands from view (start with a fresh slate).

clear

πŸ†• mkdir & touch β€” Create Things

  • mkdir website: Creates a new folder.
  • touch index.html: Creates an empty file.

πŸ—£οΈ echo β€” Print and Write Content

1️⃣ Print Text

echo Hello World

2️⃣ Create or Overwrite (>)

Using > writes text into a file. If the file exists, it replaces everything inside. echo "My first webpage" > index.html

3️⃣ Append Content (>>)

Using >> adds text to the end of a file without deleting what is already inside. echo "This line was added later" >> index.html

CommandWhat It Does
echo "text" > file.txtCreates or overwrites existing content
echo "text" >> file.txtAppends text to the end of the file

πŸ“– cat β€” View and Create Content

  • View: cat index.html (Displays what is inside).
  • Create/Overwrite: cat > notes.txt (Type content, then press CTRL+D to save).
  • Append: cat >> notes.txt (Add content, press CTRL+D to save).

πŸ“‹ cp & mv β€” Copy and Move

  • Copy File: cp index.html about.html
  • Copy Folder: cp -r website backup-website (The -r is required for folders).
  • Rename/Move: mv index.html home.html

❌ rm & rmdir β€” Delete

  • Delete Empty Folder: rmdir old-folder
  • Delete File: rm file.txt
  • Delete Folder & Content: rm -r website

⚠️ CAUTION: Deletions are instantaneous and permanent. There is no Recycle Bin.


πŸ§ͺ Practice Exercise

Try the following commands step by step:

mkdir web-practice
cd web-practice
touch index.html
echo "Hello Web" > index.html
echo "Learning terminal commands" >> index.html
cat index.html
mkdir assets
cp index.html assets/
ls -l

πŸ–ΌοΈ Terminal Example

Terminal example


πŸŽ₯ Lesson Video

<video controls width="100%"> <source src="/videos/lesson-3-terminal-basics.mp4" type="video/mp4"> Your browser does not support the video tag. </video>

πŸ“ Project Task: Terminal Mastery

Using only the terminal:

  1. Create a folder named my-first-website
  2. Inside it, create index.html and about.html.
  3. Add the text "Welcome to my website" inside index.html using echo.
  4. Append another line to index.html using echo >>.
  5. Create a file called notes.txt using cat and write two lines inside.
  6. Append a third line to notes.txt using cat >>.
  7. Copy index.html into a new folder called backup.
  8. Rename about.html to about-me.html.
  9. Verify your folder structure using ls -l.

Knowledge Check

Complete this quick quiz to verify your understanding and unlock the next module.