Skip to content
PSUT / IoTEngineering learning studio
WORKSPACE
Offline-first portalDr. Mohammad Alja’afreh
Distributed Ledger StudioBlockchain for IoTExperimentsWorkspaces
ENGINEERING WORKSPACE
Home/WSL Laboratories/Linux & WSL Command Center · PSUT IoT Learning Studio
PSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
Foundations · Command Center
IoT Programming and Applications

Master the Linux terminal.

Learn the commands you will use in every IoT lab. Copy exact examples into the correct terminal, or practice safely in the browser before touching real files.

Know which shell you are using

WINDOWS · PowerShell
PS C:\Users\Student>

Run wsl --list --verbose, install or stop Ubuntu here.

UBUNTU · Bash
student@ubuntu:~$

Run cd, ls, sudo apt, python and service commands here.

PYTHON · REPL
>>>

Only Python statements here. Type exit() to return to Bash.

Do not copy prompt symbols. In VS Code, choose Terminal → New Terminal inside the WSL workspace; check the lower-left remote indicator. Use a separate Windows PowerShell window for WSL management. Ctrl+C stops most foreground programs; Tab completes names, ↑ recalls a previous command, Ctrl+L clears the screen.

Interactive learning · simulated filesystem

Virtual command terminal

Practice navigation, files, WSL launch and Python commands. This browser model never executes commands on your computer. The paths and outputs are examples, not your actual machine.

● ● ●Ubuntu BashSIMULATED
Dr. Mohammad · terminal coach

Try pwd to identify the current directory. Then use ls to see its contents.

Only a documented subset is supported. Package installs, destructive commands and real services are not executed in this simulator.

Two daily workflows

Open and run a real Python lab

1. Open Windows PowerShell and start Ubuntu:

Windows PowerShell
wsl -d Ubuntu-24.04
✓ Expected: The selected Linux shell opens; on first launch complete account creation. The prompt ends in $. No physical board is connected by this command.

2. In Ubuntu, activate the installed toolkit and run Lab 29:

Ubuntu Bash
source ~/psut-wsl/activate.sh
cd ~/psut-wsl/labs/python/lab29
pwd
ls
python blink_gpiozero.py
✓ Expected: The fake GPIO17 output alternates HIGH/LOW every 0.5 seconds. Press Ctrl+C to stop.
Expected result for each action (5)
  1. source ~/psut-wsl/activate.shThe toolkit virtual environment is selected in this terminal, usually with (.venv) in the prompt. Verify which python points into ~/psut-wsl/.venv.
  2. cd ~/psut-wsl/labs/python/lab29Normally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
  3. pwdAn absolute Linux path appears, matching the directory selected in the preceding step.
  4. lsThe requested files/directories are listed; compare names and permissions with the guide. An empty directory can produce no output.
  5. python blink_gpiozero.pyThe fake GPIO17 output alternates HIGH/LOW every 0.5 seconds. Press Ctrl+C to stop.

3. Press Ctrl+C to stop. To reopen the workspace use cd ~/psut-wsl then code ..

Open Lab P29 →

Practice files without touching lab code

Use a dedicated folder. If you already have a practice file with important contents, choose a new filename before writing.

Ubuntu Bash
mkdir -p ~/linux-practice
cd ~/linux-practice
pwd
ls
mkdir -p Documents
cd Documents
touch test.txt
ls -l test.txt
chmod u+x test.txt
ls -l test.txt
cd ..
tree -L 2 .
✓ Expected: An indented directory tree.
Expected result for each action (12)
  1. mkdir -p ~/linux-practiceNormally silent. The requested directory exists afterward; verify with ls -d.
  2. cd ~/linux-practiceNormally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
  3. pwdAn absolute Linux path appears, matching the directory selected in the preceding step.
  4. lsThe requested files/directories are listed; compare names and permissions with the guide. An empty directory can produce no output.
  5. mkdir -p DocumentsNormally silent. The requested directory exists afterward; verify with ls -d.
  6. cd DocumentsNormally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
  7. touch test.txtls -l test.txt shows the file.
  8. ls -l test.txtThe requested files/directories are listed; compare names and permissions with the guide. An empty directory can produce no output.
  9. chmod u+x test.txtNormally silent. Verify with ls -l or stat; a private directory should be 700 and a private credential file 600 where specified.
  10. ls -l test.txtThe requested files/directories are listed; compare names and permissions with the guide. An empty directory can produce no output.
  11. cd ..Normally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
  12. tree -L 2 .An indented directory tree.

Verify the x permission and the directory tree. This follows the original Lab 3 practice.

Open Lab R3 →

Search the command library

Ubuntu Bash

02 · Files & directories

Create a practice directory

-p creates missing parents and does not fail if the directory exists.

Ubuntu Bash
mkdir -p ~/linux-practice
✓ Expected: Normally silent. The requested directory exists afterward; verify with ls -d.

Check: ls ~/linux-practice succeeds.

Enter the practice directory

Use this folder for all examples in this section.

Ubuntu Bash
cd ~/linux-practice
✓ Expected: Normally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.

Check: pwd ends in /linux-practice.

Make a subdirectory

Create a child named Documents.

Ubuntu Bash
mkdir -p Documents
✓ Expected: Normally silent. The requested directory exists afterward; verify with ls -d.

Check: ls shows Documents.

Create an empty file

Creates a file if missing; otherwise updates its timestamp.

Ubuntu Bash
touch test.txt
✓ Expected: ls -l test.txt shows the file.

Check: ls -l test.txt shows the file.

Write text to a file

> creates or overwrites test.txt. Use only your practice file.

Ubuntu Bash
echo "Hello IoT" > test.txt
✓ Expected: cat test.txt prints Hello IoT.

Check: cat test.txt prints Hello IoT.

Read the file

Print its full contents.

Ubuntu Bash
cat test.txt
✓ Expected: Hello IoT if you completed the previous example.

Check: Hello IoT if you completed the previous example.

Append text

>> adds to the end instead of replacing existing content.

Ubuntu Bash
echo "Second line" >> test.txt
✓ Expected: cat shows both lines.

Check: cat shows both lines.

Copy a file

Copies the source to the destination; an existing destination can be overwritten.

Ubuntu Bash
cp test.txt backup.txt
✓ Expected: ls shows both files.

Check: ls shows both files.

Rename or move a file

Rename the copy, leaving test.txt unchanged.

Ubuntu Bash
mv backup.txt notes.txt
✓ Expected: ls shows notes.txt, not backup.txt.

Check: ls shows notes.txt, not backup.txt.

Edit a file in the terminal

Edit text; Ctrl+O then Enter saves; Ctrl+X exits.

Ubuntu Bash
nano test.txt
✓ Expected: cat shows your saved changes.

Check: cat shows your saved changes.

View the first five lines

Useful for checking the start of a CSV or log.

Ubuntu Bash
head -n 5 test.txt
✓ Expected: Up to five lines appear.

Check: Up to five lines appear.

View the last five lines

Useful for checking recent records.

Ubuntu Bash
tail -n 5 test.txt
✓ Expected: Up to five lines appear.

Check: Up to five lines appear.

Find matching text

-n shows matching line numbers.

Ubuntu Bash
grep -n "IoT" test.txt
✓ Expected: Lines containing IoT, or no output if no match.

Check: Lines containing IoT, or no output if no match.

Find text files

Search recursively below the current folder.

Ubuntu Bash
find . -name "*.txt"
✓ Expected: Matching relative paths.

Check: Matching relative paths.

Change user execute permission

Adds execute permission for the owner; does not turn a text file into a program.

Ubuntu Bash
chmod u+x test.txt
✓ Expected: Normally silent. Verify with ls -l or stat; a private directory should be 700 and a private credential file 600 where specified.

Check: ls -l shows x in the owner permission field.

Delete a practice file

-i asks before deleting. Deletion in Linux is normally not sent to the Recycle Bin.

Ubuntu Bash
rm -i notes.txt
✓ Expected: Answer y only if notes.txt is your disposable copy.

Check: Answer y only if notes.txt is your disposable copy.

Remove an empty directory

Fails if the directory contains files.

Ubuntu Bash
rmdir Documents
✓ Expected: Documents disappears if empty.

Check: Documents disappears if empty.

Ubuntu Bash

03 · Python, VS Code & execution

Check system Python

Print the installed Python 3 version.

Ubuntu Bash
python3 --version
✓ Expected: The installed version is printed. For this toolkit InfluxDB must be 2.x; version numbers otherwise depend on installation.

Check: Python 3.x.

Activate the lab environment

Loads the packaged virtual environment and fakepi support for this terminal. Requires completed setup.

Ubuntu Bash
source ~/psut-wsl/activate.sh
✓ Expected: The toolkit virtual environment is selected in this terminal, usually with (.venv) in the prompt. Verify which python points into ~/psut-wsl/.venv.

Check: Prompt shows (.venv); which python points inside the toolkit.

Find the active interpreter

Check which executable will run when you type python.

Ubuntu Bash
which python
✓ Expected: The interpreter path ends in /psut-wsl/.venv/bin/python when the toolkit is active.

Check: With activation, path includes psut-wsl/.venv/bin/python.

List Python packages

Uses pip belonging to the active interpreter.

Ubuntu Bash
python -m pip list
✓ Expected: Installed package names and versions.

Check: Installed package names and versions.

Inspect a package

Check whether gpiozero is installed in the selected environment.

Ubuntu Bash
python -m pip show gpiozero
✓ Expected: Package details including Location.

Check: Package details including Location.

Go to a real lab

Navigate to the supplied GPIO Zero LED example.

Ubuntu Bash
cd ~/psut-wsl/labs/python/lab29
✓ Expected: Normally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.

Check: ls shows blink_gpiozero.py.

Run a lab program

After activating and entering Lab 29, execute the supplied program. It blinks in the background and waits in pause().

Ubuntu Bash
python blink_gpiozero.py
✓ Expected: The fake GPIO17 output alternates HIGH/LOW every 0.5 seconds. Press Ctrl+C to stop.

Check: Foreground remains running; fake GPIO state changes may be logged. Stop with Ctrl+C.

Run one Python expression

-c runs a short Python statement directly from Bash; no file required.

Ubuntu Bash
python -c "print(2 + 3)"
✓ Expected: 5 is printed.

Check: 5

Open interactive Python

Enter the >>> prompt after activation. Type print(2 + 3), then exit() to return to Bash.

Ubuntu Bash
python
✓ Expected: Python starts and shows the >>> prompt. Use exit() to return to Bash.

Check: >>> appears; shell commands do not belong here.

Leave the virtual environment

Returns the shell to its previous Python environment.

Ubuntu Bash
deactivate
✓ Expected: (.venv) disappears.

Check: (.venv) disappears.

Open the toolkit in VS Code

From Ubuntu, open the whole workspace in the WSL remote window. Requires VS Code and WSL extension.

Ubuntu Bash
cd ~/psut-wsl
code .
✓ Expected: VS Code opens the current directory; confirm the WSL remote indicator for Linux projects.
Expected result for each action (2)
  1. cd ~/psut-wslNormally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
  2. code .VS Code opens the current directory; confirm the WSL remote indicator for Linux projects.

Check: VS Code opens the toolkit; status bar indicates WSL.

Install all toolkit services

Run once after copying the toolkit. Installs base Python and optional services; requires internet and sudo.

Ubuntu Bash
bash ~/psut-wsl/setup_wsl.sh --all
✓ Expected: The installer completes and returns to the prompt. Verify the selected services and run the toolkit self-test; package logs may vary.

Check: Installer completes; run self-test next. See Setup for details.

Run the toolkit self-test

Checks core setup and reports failures.

Ubuntu Bash
bash ~/psut-wsl/tools/selftest.sh
✓ Expected: The toolkit reports checks for the installed components. Review any FAIL or unavailable optional service before continuing.

Check: Inspect the result and fix any failed checks.

Ubuntu Bash

04 · Linux system, processes & services

Show your Linux username

Identify the current Linux account.

Ubuntu Bash
whoami
✓ Expected: Your Linux username.

Check: Your Linux username.

Identify Ubuntu

Read distribution information.

Ubuntu Bash
cat /etc/os-release
✓ Expected: Ubuntu and version ID, e.g. 24.04.

Check: Ubuntu and version ID, e.g. 24.04.

Inspect the kernel

Show kernel and architecture information.

Ubuntu Bash
uname -a
✓ Expected: Linux kernel details; WSL kernel is not a Pi kernel.

Check: Linux kernel details; WSL kernel is not a Pi kernel.

Check free disk space

Report filesystem capacity in readable units.

Ubuntu Bash
df -h
✓ Expected: Size, Used and Avail columns.

Check: Size, Used and Avail columns.

Check memory

Report memory and swap usage.

Ubuntu Bash
free -h
✓ Expected: Mem and Swap rows.

Check: Mem and Swap rows.

List running processes

Inspect process IDs and command lines.

Ubuntu Bash
ps aux
✓ Expected: A process table.

Check: A process table.

Watch live processes

Interactive CPU and memory monitor. Press q to leave.

Ubuntu Bash
top
✓ Expected: Continuously updating process list.

Check: Continuously updating process list.

Review recent Bash commands

Shows commands in this shell history; do not share secrets from it.

Ubuntu Bash
history
✓ Expected: Numbered command history.

Check: Numbered command history.

Clear terminal display

Clears the screen, not your files.

Ubuntu Bash
clear
✓ Expected: A clean terminal.

Check: A clean terminal.

Refresh Ubuntu package index

Downloads package metadata. It does not upgrade installed programs.

Ubuntu Bash
sudo apt update
✓ Expected: Repository metadata is refreshed and the prompt returns without repository errors.

Check: Package lists read successfully.

Install a package

Installs the tree utility using Ubuntu package manager.

Ubuntu Bash
sudo apt install -y tree
✓ Expected: Packages are installed or already up to date; the prompt returns. Verify executable availability before using them.

Check: tree --version works.

Start the MQTT service

Requires Mosquitto installed and systemd enabled in WSL.

Ubuntu Bash
sudo systemctl start mosquitto
✓ Expected: Normally no output on success. Run systemctl is-active for the named service and confirm active; inspect logs if it fails.

Check: systemctl is-active mosquitto prints active.

Inspect a service

Show service state and recent log entries.

Ubuntu Bash
systemctl status mosquitto --no-pager
✓ Expected: The service status and recent log lines appear. Look for Active: active (running) for a running service.

Check: Active: active (running), if healthy.

Restart Mosquitto

Interrupts connections briefly; use after config changes.

Ubuntu Bash
sudo systemctl restart mosquitto
✓ Expected: Normally no output on success. Run systemctl is-active for the named service and confirm active; inspect logs if it fails.

Check: Service active again; publisher may need reconnect.

Read service logs

Inspect the last 30 log lines for startup or listener errors.

Ubuntu Bash
sudo journalctl -u mosquitto -n 30 --no-pager
✓ Expected: Recent service log entries appear. Check errors and timestamps; redact credentials before sharing.

Check: Recent service log entries.

List listening TCP ports

-l listening, -t TCP, -n numeric addresses.

Ubuntu Bash
ss -ltn
✓ Expected: Socket table appears; check the required protocol, port and connection state. Empty results may be normal without active connections.

Check: Look for 1884, 1880, 8086 or 3000 when services are running.

Show Linux IP addresses

Lists assigned Linux addresses; WSL IP may change.

Ubuntu Bash
hostname -I
✓ Expected: IP addresses assigned to the Linux environment are printed; actual addresses vary.

Check: One or more addresses.

Check InfluxDB health

Queries local InfluxDB health; requires the service running.

Ubuntu Bash
curl -fsS http://127.0.0.1:8086/health
✓ Expected: InfluxDB health JSON includes status pass when the service is healthy; this does not verify bucket permissions or stored data.

Check: A JSON health response; failure means inspect service first.

Subscribe to a local test topic

Run in Terminal A. Keep it open; requires local Mosquitto configured by Setup.

Ubuntu Bash
mosquitto_sub -h 127.0.0.1 -p 1884 -t linux-practice/test -v
✓ Expected: The subscriber remains open. Once a matching publisher sends data, topic and JSON payload appear; an initially blank screen is normal.

Check: Waits for a message; use the next command in Terminal B.

Publish a test MQTT message

Run in Terminal B after starting subscriber. Local teaching topic only.

Ubuntu Bash
mosquitto_pub -h 127.0.0.1 -p 1884 -t linux-practice/test -m "hello"
✓ Expected: Usually silent on success. Confirm the exact topic and payload in a separate subscriber; this is not proof of database storage.

Check: Terminal A prints linux-practice/test hello.

Windows PowerShell

05 · WSL management from Windows

List installed distributions

Show distribution names, running state and WSL version. Use the exact name in other commands.

Windows PowerShell
wsl --list --verbose
✓ Expected: A table of installed distributions, STATE and VERSION appears. Verify the intended distribution is listed with VERSION 2.

Check: Ubuntu-24.04 should appear with VERSION 2 after installation.

List available distributions

Show installable Linux distributions. Requires internet.

Windows PowerShell
wsl --list --online
✓ Expected: List includes distribution names.

Check: List includes distribution names.

Install Ubuntu 24.04

Use Administrator PowerShell if Ubuntu is not installed. Restart if requested and create the Linux user.

Windows PowerShell
wsl --install -d Ubuntu-24.04
✓ Expected: Installation completes or Windows requests a restart. On first launch create your Linux username and password; the prompt resembles username@PC:~$. Verify the distribution with wsl -l -v (VERSION 2). WSL is a Linux environment, not a physical Raspberry Pi.

Check: wsl -l -v lists Ubuntu-24.04.

Open Ubuntu

Start the named distribution even if Kali or another Ubuntu is the default.

Windows PowerShell
wsl -d Ubuntu-24.04
✓ Expected: The selected Linux shell opens; on first launch complete account creation. The prompt ends in $. No physical board is connected by this command.

Check: Linux Bash prompt appears.

Set default distribution

Makes Ubuntu-24.04 the default when running wsl. Does not delete other distributions.

Windows PowerShell
wsl --set-default Ubuntu-24.04
✓ Expected: An asterisk marks Ubuntu-24.04 in wsl -l -v.

Check: An asterisk marks Ubuntu-24.04 in wsl -l -v.

Choose WSL 2 for future installs

Changes the default for new distributions, not existing installations.

Windows PowerShell
wsl --set-default-version 2
✓ Expected: Command completes successfully.

Check: Command completes successfully.

Convert an existing distribution

Only needed if the distribution is version 1. Back up first and stop active programs.

Windows PowerShell
wsl --set-version Ubuntu-24.04 2
✓ Expected: wsl -l -v shows VERSION 2.

Check: wsl -l -v shows VERSION 2.

Check WSL settings

Display default distribution and WSL configuration information.

Windows PowerShell
wsl --status
✓ Expected: Default distribution/version information.

Check: Default distribution/version information.

Check WSL components

Print WSL and kernel component versions (modern WSL).

Windows PowerShell
wsl --version
✓ Expected: Version details.

Check: Version details.

Update WSL

Updates the WSL runtime, not Ubuntu apt packages. May need admin rights.

Windows PowerShell
wsl --update
✓ Expected: Update completes or reports latest available version.

Check: Update completes or reports latest available version.

Run one Linux command from PowerShell

The -- separates WSL options from the Linux command. Working directory can reflect the Windows current directory.

Windows PowerShell
wsl -d Ubuntu-24.04 -- pwd
✓ Expected: A Linux path is printed; PowerShell prompt returns.

Check: A Linux path is printed; PowerShell prompt returns.

Inspect Linux files without opening a shell

Runs ls inside Ubuntu then returns to PowerShell.

Windows PowerShell
wsl -d Ubuntu-24.04 -- ls -la /home
✓ Expected: Linux home directory listing.

Check: Linux home directory listing.

Stop only Ubuntu

Stops processes in the selected distro. Save work before executing.

Windows PowerShell
wsl --terminate Ubuntu-24.04
✓ Expected: wsl -l -v shows Stopped for Ubuntu.

Check: wsl -l -v shows Stopped for Ubuntu.

Stop all WSL distributions

Stops all running distributions and the WSL 2 VM, including IoT services. Save work first.

Windows PowerShell
wsl --shutdown
✓ Expected: wsl -l -v shows stopped distributions.

Check: wsl -l -v shows stopped distributions.

Show WSL usage

List supported WSL command options.

Windows PowerShell
wsl --help
✓ Expected: Help text.

Check: Help text.

Back up Ubuntu

Save work, terminate Ubuntu first, then export to your Windows home. Check free disk space and avoid overwriting an existing backup.

Windows PowerShell
wsl --export Ubuntu-24.04 "$HOME/Ubuntu-24.04-backup.tar"
✓ Expected: Backup TAR file appears in your Windows user folder.

Check: Backup TAR file appears in your Windows user folder.

Ubuntu Bash

06 · Essential shell skills

Return from Ubuntu to Windows

If launched from PowerShell, exits the current Linux shell. Does not necessarily stop all WSL processes.

Ubuntu Bash
exit
✓ Expected: PowerShell prompt returns.

Check: PowerShell prompt returns.

Run a Windows WSL command from Bash

Use wsl.exe inside Ubuntu to invoke the Windows executable. Normally manage WSL in PowerShell instead.

Ubuntu Bash
wsl.exe --list --verbose
✓ Expected: A table of installed distributions, STATE and VERSION appears. Verify the intended distribution is listed with VERSION 2.

Check: Windows list of distributions.

Read a command manual

Open ls manual; press q to leave.

Ubuntu Bash
man ls
✓ Expected: Manual page appears if installed.

Check: Manual page appears if installed.

Read command options

Show quick usage without opening a manual.

Ubuntu Bash
ls --help
✓ Expected: The requested files/directories are listed; compare names and permissions with the guide. An empty directory can produce no output.

Check: ls options and syntax.

Run two commands conditionally

&& executes ls only if pwd succeeds.

Ubuntu Bash
pwd && ls
✓ Expected: An absolute Linux path appears, matching the directory selected in the preceding step.

Check: Current path followed by entries.

Pipe output between commands

| sends output of ls to head; prints at most five lines.

Ubuntu Bash
ls -la | head -n 5
✓ Expected: The requested files/directories are listed; compare names and permissions with the guide. An empty directory can produce no output.

Check: First five listing lines.

Destructive WSL commands — read before using

Warning: unregistering a distribution permanently deletes its Linux filesystem, installed programs and data. To remove a distribution deliberately, first export a backup, verify the exact name with wsl -l -v, and consult the official instructions for wsl --unregister. No executable deletion command is supplied here. Shutdown and terminate do not uninstall a distribution.

References and related labs

Microsoft Learn · Basic commands for WSL · Lab R3 · Linux commands · Lab R4 · WSL access · Setup