💻 Command Line Basics
The terminal might look scary at first, but it's one of the most powerful tools a developer has. This guide covers everything you need to navigate, create files, and run your programs.
📑 Jump To
🤔 What Is the Command Line?
The command line (also called the terminal, shell, or console) is a text-based way to interact with your computer. Instead of clicking icons and menus, you type commands and press Enter.
It might feel slower at first, but once you learn the basics, it's actually faster for many tasks — especially running code. Every professional developer uses the command line daily.
Key vocabulary:
- Terminal — The application window where you type commands.
- Shell — The program that interprets your commands (bash, zsh, PowerShell).
- Prompt — The text that appears before your cursor, showing you where you are (e.g.,
C:\Users\you>or~/projects$). - Directory — Another word for "folder."
- Path — The address of a file or folder (e.g.,
/home/user/projects/hello.py).
🚪 Opening Your Terminal
Windows
- PowerShell: Press Win, type "PowerShell", press Enter.
- Command Prompt: Press Win+R, type
cmd, press Enter. - VS Code: Press Ctrl+` (backtick) to open the built-in terminal.
This course recommends PowerShell or the VS Code terminal on Windows.
macOS
- Terminal.app: Open Finder → Applications → Utilities → Terminal.
- Spotlight: Press Cmd+Space, type "Terminal", press Enter.
- VS Code: Press Ctrl+` to open the built-in terminal.
Linux
- Press Ctrl+Alt+T on most distributions.
- Or find "Terminal" in your applications menu.
📁 Creating & Managing Files
Create a folder — mkdir
Make Directory. Creates a new folder.
# Create a single folder:
mkdir my-project
# Create nested folders at once:
mkdir -p my-project/src/utils
On Windows cmd, use mkdir my-project\src\utils (backslashes, and it auto-creates parents).
Create / view a file
# Create an empty file:
# touch hello.py
# View a file's contents:
# cat hello.py
# View a long file with scrolling:
# less hello.py
// Create an empty file:
// New-Item hello.js
// View a file's contents:
// Get-Content hello.js
// (or: cat hello.js)
// Create an empty file:
// type nul > hello.cs
// View a file's contents:
// type hello.cs
Copy, move, and delete
| Action | macOS / Linux | Windows (PowerShell) | Windows (cmd) |
|---|---|---|---|
| Copy a file | cp file.py backup.py | Copy-Item file.js backup.js | copy file.cs backup.cs |
| Move / rename | mv old.py new.py | Move-Item old.js new.js | move old.cs new.cs |
| Delete a file | rm file.py | Remove-Item file.js | del file.cs |
| Delete a folder | rm -r folder/ | Remove-Item -Recurse folder | rmdir /s folder |
⚠️ Be careful with delete commands. There's no recycle bin in the terminal — deleted files are gone for good.
▶️ Running Your Programs
This is what you'll do most often in this course: write code in VS Code, then switch to the terminal to run it.
# Run a Python file:
# python hello.py
# (or on macOS/Linux:)
# python3 hello.py
# Run with arguments:
# python hello.py --name Ray
# Start an interactive Python session:
# python
# (type exit() to leave)
// Run a JavaScript file with Node.js:
// node hello.js
// Run with arguments:
// node hello.js --name Ray
// Start an interactive Node session (REPL):
// node
// (press Ctrl+C twice to leave)
// First, create a project (if you haven't):
// dotnet new console -n MyApp
// cd MyApp
// Run the project:
// dotnet run
// Build without running:
// dotnet build
🎓 Instructor Note: Terminal Workflow
Demonstrate the "edit-save-switch-run" loop early and often. Many beginners forget to save their file before running, or they run the command in the wrong directory. Encourage using VS Code's built-in terminal so they don't have to switch windows.
⌨️ Time-Saving Shortcuts
These keyboard tricks will make you faster in the terminal immediately:
| Shortcut | What It Does |
|---|---|
| Tab | Auto-complete file and folder names. Press twice to see all options. |
| ↑ / ↓ | Scroll through your command history. Re-run previous commands quickly. |
| Ctrl+C | Cancel the currently running command. Use when a program is stuck. |
| Ctrl+L | Clear the screen (same as typing clear). |
| Ctrl+A | Move cursor to the beginning of the line. |
| Ctrl+E | Move cursor to the end of the line. |
history | Show all recent commands. On Windows PowerShell: Get-History. |
clear | Clear the terminal screen. On Windows cmd: cls. |
🚫 Common Mistakes
Running code from the wrong directory
If you see "file not found" when running python hello.py, you're probably in the wrong folder. Use pwd to check where you are and ls to confirm your file is there.
Forgetting to save before running
Your terminal runs whatever is saved on disk, not what's on screen in your editor. Press Ctrl+S (or Cmd+S on Mac) before switching to the terminal.
Spaces in folder names
Folder names with spaces cause problems in the terminal. Use hyphens or underscores instead: my-project not my project. If you must use a path with spaces, wrap it in quotes: cd "My Documents".
Backslashes vs. forward slashes
Windows uses backslashes (\) in paths; macOS and Linux use forward slashes (/). PowerShell accepts both. If you copy a path from Windows Explorer, it will have backslashes — that's fine in PowerShell but won't work in bash/zsh.
📋 Quick Reference
| Task | macOS / Linux | Windows (PowerShell) |
|---|---|---|
| Where am I? | pwd | pwd |
| List files | ls | ls or dir |
| Change directory | cd folder | cd folder |
| Go up one level | cd .. | cd .. |
| Home directory | cd ~ | cd ~ |
| Create folder | mkdir name | mkdir name |
| Create file | touch file.txt | New-Item file.txt |
| View file | cat file.txt | cat file.txt |
| Copy file | cp a.txt b.txt | cp a.txt b.txt |
| Move / rename | mv a.txt b.txt | mv a.txt b.txt |
| Delete file | rm file.txt | rm file.txt |
| Clear screen | clear | cls or clear |
| Run Python | python3 file.py | python file.py |
| Run JavaScript | node file.js | node file.js |
| Run C# | dotnet run | dotnet run |