Course 0W · Module 2 Windows Terminal & PowerShell
Python for Actuarial Students · Course 0W
Module 2

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
50 min
Concepts & worked examples
45 min
Terminal scavenger hunt
Part 1

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?

TerminalThe window: draws text, tabs, colors, fonts.

Windows Terminal
talks to →
ShellThe interpreter: reads your command and runs it.

PowerShell, cmd, bash
runs →
ProgramsThe actual work.

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

  1. Open Windows Terminal → Ctrl+, (Settings)
  2. Startup → Default profile → PowerShell (the black icon, not “Windows PowerShell”)
  3. Default terminal application → Windows Terminal
  4. Save

Pin Windows Terminal to the taskbar. From now on, it’s your cockpit.

SetupTwo PowerShells? Here’s the difference

Windows PowerShell 5.1PowerShell 7+
Programpowershell.exepwsh.exe
Comes withWindows (frozen, maintenance only)Separate install, actively developed
Runs onWindows onlyWindows, macOS, Linux
Default text encodingMixed (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 PowerShell

C:\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 >.

Part 2

Getting Around

Where am I? What’s here? How do I go there?

NavigationThe big three: pwd, ls, cd

QuestionCommand
Where am I?pwd
What’s here?ls or dir
Go therecd <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

CommandGoes to
cd dataThe 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_workAn 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
AliasCmdletDoes
pwdGet-LocationShow current folder
cdSet-LocationChange folder
ls, dirGet-ChildItemList contents
cp, copyCopy-ItemCopy
mv, moveMove-ItemMove / rename
rm, delRemove-ItemDelete
cat, typeGet-ContentShow a file
cls, clearClear-HostClear 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 matches

Shift+Tab

Cycle backwards

Ctrl+Space

Show a menu of all matches

Tab-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.

Part 3

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'
QuotesBehavior
'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.

Part 4

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-ChildItemlist every file
|
Where-Objectkeep the big ones
|
Sort-Objectlargest first
|
Select-Objecttop 5
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

KeysAction
Ctrl+CInterrupt the running program
↑ / ↓Previous / next command in history
Ctrl+RSearch history as you type
Ctrl+L / clsClear the screen
EscErase the current line
Home / EndJump to start / end of line
Ctrl+← / →Jump a word at a time

Windows Terminal extras

Ctrl+Shift+TNew tab
Alt+Shift+DSplit pane
Ctrl+V / right-clickPaste
Select text + Ctrl+CCopy (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.

  1. Setup — run the setup script on the next slide to create a hidden treasure trail in C:\actuarial_work\hunt
  2. Hunt — follow the clues through deeply nested folders
  3. Build — create a clean project tree and move the data files into it
  4. 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

  1. cd into hunt and read START_HERE.txt
  2. Find and read the hidden clue (ls -Force)
  3. Count the lapses across all CSVs (hint: ls -Recurse -Filter *.csv | Select-String LAPSE, then pipe to Measure-Object)
  4. Write the count to answer.txt with >; check with cat

Build

  1. Create C:\actuarial_work\lapse_study\data\raw in one command
  2. Copy both policies.csv files into raw, renaming them north_q3.csv and south_q1.csv
  3. Show the first 2 lines of each with cat -Head
  4. Save a listing of lapse_study (ls -Recurse) to inventory.txt
  5. Bonus: delete the hunt folder — safely, with -WhatIf first

ReferenceCheat sheet

Navigate

pwd · ls · ls -Force
cd path · cd .. · cd ~ · cd -

Files

mkdir · ni file
cp a b · mv a b
rm x · rm dir -Recurse

Inspect

cat f · cat f -Head 5
Select-String pat files
… | more

Combine

a | b pipe
> overwrite · >> append

Keys

Tab · ↑ · Ctrl+C
Ctrl+R · Ctrl+L

Help

Get-Help cmd -Examples
Get-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
Up next
Module 3

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?