Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Open In Colab Open In Kaggle

The terminal is a text interface for talking to your computer directly, without a mouse. Every command below has an exact unix form (macOS and Linux) and an exact PowerShell form (Windows); do not try to memorise either column — bookmark this page and copy what you need.

Opening a terminal

  • macOS — in Applications -> Utilities (or search “Terminal”); the default shell is zsh.

  • Linux — usually Ctrl+Alt+T, or a “Terminal” application in your desktop’s menu; the default shell is usually bash.

  • Windows — search “PowerShell” (built in), or install the newer Windows Terminal app from the Microsoft Store. For a real unix-like shell, see the WSL box below.

Three commands cover the basics: print the working directory, list its contents, change directory.

# macOS (zsh) and Linux (bash)
pwd                   # print working directory
ls -la                # list all files, long format
cd ../data            # up one level, then into data/
# Windows (PowerShell)
Get-Location          # print working directory (alias: pwd)
Get-ChildItem         # list files (aliases: ls, dir)
Set-Location ..\data  # change directory (alias: cd ..\data)

The most visible difference is the path separator: unix uses /, Windows uses \. Hard-coding either makes code non-portable — see the pathlib section below.

Files and directories

# macOS / Linux
mkdir results                     # create a directory
touch notes.txt                   # create an empty file
cp notes.txt notes_backup.txt     # copy
mv notes_backup.txt archive/      # move (or rename)
rm notes_backup.txt               # delete a file
cat notes.txt                     # print a file's contents
# Windows (PowerShell)
New-Item -ItemType Directory results   # create a directory (alias: mkdir)
New-Item notes.txt                     # create an empty file
Copy-Item notes.txt notes_backup.txt   # copy (alias: cp)
Move-Item notes_backup.txt archive\    # move or rename (alias: mv)
Remove-Item notes_backup.txt           # delete a file (alias: rm, del)
Get-Content notes.txt                  # print a file's contents (alias: cat)

Paths in python with pathlib

Never build a path by string concatenation; pathlib handles the / vs \ difference for you, and works identically on every operating system.

posix
/home/runner/work/2026_MLEES_book/2026_MLEES_book/appendix
data/raw/temperature.csv
data/raw/temperature.csv
data\raw\temperature.csv

Running python code

python script.py            # run a script
python -c "print(2 + 2)"    # run a one-line snippet
python                      # start an interactive interpreter (exit() to leave)

Keep a project’s dependencies isolated in a virtual environment, rather than installing packages globally:

# macOS / Linux
python -m venv .venv
source .venv/bin/activate
# Windows (PowerShell)
python -m venv .venv
.venv\Scripts\Activate.ps1

Once activated, python and pip install inside that terminal only affect this project. The section below covers uv, a faster, modern alternative to this venv-then-activate-then-pip sequence.

uv

uv is a fast, modern replacement for pip and venv: one tool that installs python itself, manages a project’s virtual environment, and resolves dependencies — all noticeably faster than the tools above. Install it once, outside any project:

# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Inside a project, uv replaces the venv-then-activate-then-pip sequence above with a few commands:

uv init                    # start a new project (creates pyproject.toml)
uv add numpy pandas        # add a dependency, resolved and installed
uv run python script.py    # run inside the project's environment, no activation needed

uv run is the command to reach for by default: the first time it runs, it creates the virtual environment and installs the project’s dependencies; every time after, it makes sure that environment is still in sync before running whatever follows. uv run jupyter lab and uv run python script.py always use the right, up-to-date environment, with no separate activation step to remember.

Useful extras

  • Tab completion — press Tab to auto-complete a file or command name; press it twice to see the options if it is ambiguous.

  • Command history — the Up/Down arrows recall previous commands; history (bash/zsh) lists them.

  • Interrupting — Ctrl+C stops a running command.

  • Getting help — command --help (most unix tools) or man command (the full manual page); PowerShell: Get-Help Command-Name.

  • Chaining — && runs the next command only if the first succeeded, in both bash/zsh and PowerShell: mkdir results && cd results.

Resources