The Command Line with Windows Terminal & PowerShell
Why programmers type instead of click — and the handful of commands that make you fluent.
Module 2 · OverviewBy the end of this module you can…
- Explain the difference between a terminal and a shell
- Install and configure Windows Terminal and PowerShell 7
- Navigate with
pwd,cd,ls— and Tab - Create, copy, move, and delete files and folders
- Read command syntax: commands, flags, arguments, quoting
- Chain commands with pipes and save output with
>/>> - Use the essential keyboard shortcuts without thinking
Why Type?
GUI vs. CLI, and the tools we’ll use.
GUI vs. CLIWhy programmers type instead of clicking
Repeatable
A command can be re-run tomorrow, exactly. A sequence of clicks can’t.
Precise
You say exactly which file and which option. No hunting through menus.
Scriptable
Save commands to a file → you’ve automated a task. That’s programming.
Shareable
Paste a command into a chat or README. Try that with a screenshot tour.
Composable
Pipe the output of one tool into another to build something new.
Universal
Python, Git, uv, pandoc… every tool in this course has a CLI first.
Think of the CLI as the formula bar of your computer: the GUI shows results; the command shows what actually happened.
VocabularyTerminal, shell, console — what’s the difference?
Windows Terminal
PowerShell, cmd, bash
python, git, uv…Analogy: the terminal is a web browser; the shell is the website you’re visiting. One Windows Terminal window can host tabs of PowerShell, cmd, and even Linux (WSL).
SetupInstall Windows Terminal & modern PowerShell
Windows Terminal
- Windows 11: already installed
- Windows 10: Microsoft Store → search “Windows Terminal” → Get
PowerShell 7 (“modern” PowerShell)
Windows ships with the older Windows PowerShell 5.1. Install version 7 alongside it:
winget install --id Microsoft.PowerShell -e
Or from the Microsoft Store: search “PowerShell”. We’ll meet winget properly in Module 3.
Make it the default
- Open Windows Terminal → Ctrl+, (Settings)
- Startup → Default profile → PowerShell (the black icon, not “Windows PowerShell”)
- Default terminal application → Windows Terminal
- Save
Pin Windows Terminal to the taskbar. From now on, it’s your cockpit.
SetupTwo PowerShells? Here’s the difference
| Windows PowerShell 5.1 | PowerShell 7+ | |
|---|---|---|
| Program | powershell.exe | pwsh.exe |
| Comes with | Windows (frozen, maintenance only) | Separate install, actively developed |
| Runs on | Windows only | Windows, macOS, Linux |
| Default text encoding | Mixed (UTF-16 for > redirection!) | UTF-8 everywhere |
| Nice extras | — | cd -, && / ||, better errors, predictive IntelliSense |
Check which one you’re in:
PS C:\Users\Jane> $PSVersionTable.PSVersion
Major Minor Patch
----- ----- -----
7 4 6
First lookReading the prompt
PS C:\Users\Jane> _
PS
You’re talking to PowerShellC:\Users\Jane
Your current working directory — the “you are here” from Module 1>
“Ready. Type a command and press Enter.”On slides and in docs, the prompt is shown for context — don’t type it. Only type what comes after >.
Getting Around
Where am I? What’s here? How do I go there?
NavigationThe big three: pwd, ls, cd
| Question | Command |
|---|---|
| Where am I? | pwd |
| What’s here? | ls or dir |
| Go there | cd <path> |
PS C:\Users\Jane> pwd
Path
----
C:\Users\Jane
PS C:\Users\Jane> cd C:\actuarial_work\sandbox
PS C:\actuarial_work\sandbox> ls
Directory: C:\actuarial_work\sandbox
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 09/29/2026 10:14 AM data
d---- 09/29/2026 10:14 AM notebooks
-a--- 09/29/2026 10:20 AM 16 model.py
Navigationcd patterns you’ll use every day
| Command | Goes to |
|---|---|
cd data | The data folder inside the current one (relative) |
cd .. | Up one level (parent) |
cd ..\.. | Up two levels |
cd ~ | Your home folder, C:\Users\Jane |
cd \ | The root of the current drive, C:\ |
cd C:\actuarial_work | An absolute path — works from anywhere |
cd - | Back to where you just were (PowerShell 7) |
D: | Switch to drive D: |
Forward slashes work too: cd C:/actuarial_work/sandbox.
Under the hoodAliases: short names for long commands
PowerShell’s real commands (cmdlets) are named Verb-Noun. The short, familiar names are aliases, so both Windows and UNIX habits work.
PS> Get-Alias ls
CommandType Name
----------- ----
Alias ls -> Get-ChildItem
| Alias | Cmdlet | Does |
|---|---|---|
pwd | Get-Location | Show current folder |
cd | Set-Location | Change folder |
ls, dir | Get-ChildItem | List contents |
cp, copy | Copy-Item | Copy |
mv, move | Move-Item | Move / rename |
rm, del | Remove-Item | Delete |
cat, type | Get-Content | Show a file |
cls, clear | Clear-Host | Clear screen |
The #1 habitTab-completion
Never type a full path. Type a few letters, then press Tab.
PS C:\> cd act⇥ → cd .\actuarial_work\
PS C:\> cd .\actuarial_work\sa⇥ → cd .\actuarial_work\sandbox\
Tab
Complete / cycle forward through matchesShift+Tab
Cycle backwardsCtrl+Space
Show a menu of all matchesTab-completion is faster and it’s a spell-checker: if Tab doesn’t complete, the thing you’re typing doesn’t exist. It also adds quotes around paths with spaces for you.
Working With Files
Create, copy, move, delete — and read the syntax of any command.
File operationsCreate, copy, move, delete
mkdir pricing # new folder
mkdir pricing\data\raw # creates nested folders in one go
New-Item -ItemType File pricing\README.md # new empty file (short form: ni)
cp C:\Users\Jane\Downloads\claims.csv pricing\data\raw\ # copy a file in
cp pricing\data -Destination backup_data -Recurse # copy a whole folder
mv pricing\data\raw\claims.csv pricing\data\claims_2025.csv # move AND rename
mv notes.txt old_notes.txt # rename in place
rm old_notes.txt # delete a file
rm backup_data -Recurse # delete a folder and everything inside
rm does not use the Recycle Bin. Deleted means gone. Add -WhatIf to preview what would be deleted: rm *.tmp -WhatIf
SyntaxAnatomy of a command
Get-ChildItem C:\actuarial_work -Filter *.csv -Recurse
Command
What to do. Always first.Arguments
What to do it to: paths, names, values.Flags / parameters
Start with-. Some take a value (-Filter *.csv); some are on/off switches (-Recurse, -Force).Getting help
Get-Help Copy-Item -Examples
Get-Command *item* # find commands by name
python --help # most other tools
You can shorten parameter names while they stay unambiguous: -Recurse → -r, -Force → -fo. Tab-complete works on parameters too: type - then Tab.
SyntaxPaths with spaces need quotes
Spaces separate arguments. So this is three arguments, not one path:
PS> cd C:\Users\Jane\OneDrive - Contoso\Documents
Set-Location: A positional parameter cannot be found
that accepts argument '-'.
Fix it with quotes:
cd "C:\Users\Jane\OneDrive - Contoso\Documents"
cd 'C:\Program Files'
| Quotes | Behavior |
|---|---|
'single' | Literal — exactly what you typed |
"double" | Expands variables: "$HOME\data" → C:\Users\Jane\data |
To run a program whose path is quoted, prefix it with & (the call operator):
& "C:\Program Files\Git\bin\git.exe" --version
This is why we named it actuarial_work, not Actuarial Work.
Pipes & Redirection
Look inside files, connect commands together, and save the results.
ViewingLook inside files without opening an app
cat data\claims.csv # whole file (Get-Content)
cat data\claims.csv -Head 5 # first 5 lines — perfect for peeking at big CSVs
cat logs\run.log -Tail 20 # last 20 lines
cat data\claims.csv | more # one screen at a time (Space = next, q = quit)
Select-String "LAPSE" data\*.csv # search inside files (like Ctrl+F across many files)
Select-String "error" logs\*.log -CaseSensitive
A 2 GB extract will crash Excel. cat big.csv -Head 5 shows you the header row instantly.
PipesThe pipe |: output of one → input of the next
Get-ChildItem C:\actuarial_work -Recurse -File |
Where-Object Length -gt 1MB |
Sort-Object Length -Descending |
Select-Object -First 5 Name, Length
cat data\claims.csv | Select-String "MOTOR" | Measure-Object # how many motor claims?
PowerShell pipes objects (with properties like Name, Length), not just text. That’s why Sort-Object Length just works.
RedirectionSave output to a file: > and >>
ls data > inventory.txt # create / OVERWRITE
Get-Date >> run_log.txt # APPEND a line
python model.py 2> errors.txt # save only error output
Select-String "LAPSE" data\*.csv > lapses.txt
> | Write to file, replacing it |
>> | Append to end of file |
2> | Redirect errors only |
> overwrites without asking. ls > model.py just destroyed your model.
In old Windows PowerShell 5.1, > writes UTF-16 text that Python and Git find odd. PowerShell 7 writes UTF-8 — one more reason to upgrade.
Muscle memoryKeyboard shortcuts every developer uses
| Keys | Action |
|---|---|
| Ctrl+C | Interrupt the running program |
| ↑ / ↓ | Previous / next command in history |
| Ctrl+R | Search history as you type |
Ctrl+L / cls | Clear the screen |
| Esc | Erase the current line |
| Home / End | Jump to start / end of line |
| Ctrl+← / → | Jump a word at a time |
Windows Terminal extras
| Ctrl+Shift+T | New tab |
| Alt+Shift+D | Split pane |
| Ctrl+V / right-click | Paste |
| Select text + Ctrl+C | Copy (only when text is selected) |
Ctrl+C means copy only if text is highlighted; otherwise it means stop.
Muscle memoryCtrl+C: the emergency brake
Some programs run until you stop them — servers, infinite loops, a Monte-Carlo run with a typo in the iteration count.
Try it now:
PS> ping -t localhost
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
... ← press Ctrl+C
Control-C
PS> _
If the terminal seems “frozen” and the prompt hasn’t come back, a program is still running. Ctrl+C first; closing the window is the last resort.
Later, uv run jupyter lab will keep running on purpose — Ctrl+C is how you shut it down cleanly.
Hands-on Lab · 45 minThe terminal scavenger hunt
Rules: mouse off the desk. Explorer closed. Everything happens in Windows Terminal.
- Setup — run the setup script on the next slide to create a hidden treasure trail in
C:\actuarial_work\hunt - Hunt — follow the clues through deeply nested folders
- Build — create a clean project tree and move the data files into it
- Report — redirect your findings into a text file
Use Tab for every path. Count how often you need it — the answer should be “constantly”.
Lab · Setup scriptCreate the hunt (paste into PowerShell)
$root = "C:\actuarial_work\hunt"
$deep = "$root\region_north\2025\q3\claims\archive"
New-Item -ItemType Directory -Force -Path $deep, "$root\region_south\2025\q1" | Out-Null
Set-Content "$root\START_HERE.txt" "Clue 1: Go deep under region_north. The next clue is HIDDEN (try ls -Force)."
Set-Content "$deep\clue2.txt" "Clue 2: Count every LAPSE in every .csv under hunt. Then find FINAL_CLUE.txt."
attrib +h "$deep\clue2.txt" # mark the file as Hidden
Set-Content "$root\region_north\2025\q3\policies.csv" "policy_id,status`nP001,IN_FORCE`nP002,LAPSE`nP003,IN_FORCE"
Set-Content "$root\region_south\2025\q1\policies.csv" "policy_id,status`nP101,LAPSE`nP102,LAPSE`nP103,IN_FORCE"
Set-Content "$root\region_south\FINAL_CLUE.txt" "Final: Put the lapse count in hunt\answer.txt using >"
The backtick-n (`n) inside double quotes is PowerShell’s newline — like \n in Python.
Lab · TasksHunt, build, report
Hunt
cdintohuntand readSTART_HERE.txt- Find and read the hidden clue (
ls -Force) - Count the lapses across all CSVs (hint:
ls -Recurse -Filter *.csv | Select-String LAPSE, then pipe toMeasure-Object) - Write the count to
answer.txtwith>; check withcat
Build
- Create
C:\actuarial_work\lapse_study\data\rawin one command - Copy both
policies.csvfiles intoraw, renaming themnorth_q3.csvandsouth_q1.csv - Show the first 2 lines of each with
cat -Head - Save a listing of
lapse_study(ls -Recurse) toinventory.txt - Bonus: delete the
huntfolder — safely, with-WhatIffirst
ReferenceCheat sheet
Navigate
pwd · ls · ls -Forcecd path · cd .. · cd ~ · cd -
Files
mkdir · ni filecp a b · mv a brm x · rm dir -Recurse
Inspect
cat f · cat f -Head 5Select-String pat files… | more
Combine
a | b pipe> overwrite · >> append
Keys
Tab · ↑ · Ctrl+C
Ctrl+R · Ctrl+L
Help
Get-Help cmd -ExamplesGet-Command *word*tool --help
RecapModule 2 checklist
- Windows Terminal is pinned and opens PowerShell 7 by default
- I can explain terminal vs. shell
- I can navigate anywhere with
cd,ls,pwd— using Tab - I can create, copy, move, rename, and delete files and folders (and I respect
rm) - I can read a command: command, arguments, flags, quotes
- I can pipe with
|and redirect with>/>> - Ctrl+C and ↑ are already reflexes
Environment Variables, the PATH & Software Installation
When you type python, how does Windows know which program you mean? And how do you install new ones?