Übung 0 – Kommandozeile (Windows)
Ziel dieser Übung
Sie lernen die wichtigsten Befehle der Kommandozeile (PowerShell) kennen und legen damit Ihren Kursordner an. Das brauchen Sie in jeder Sitzung, um Python-Programme zu starten.
Wozu die Kommandozeile?
Im PowerShell steuern Sie den Computer mit getippten Befehlen statt mit der Maus. In diesem Kurs nutzen Sie ihn, um
- in den Ordner mit Ihren Python-Dateien zu wechseln,
- Programme zu starten, z. B.
python hallo.py, - später Pakete wie Pygame zu installieren.
Begriffe: PowerShell (und das ältere CMD) gibt es unter Windows, das Terminal unter macOS und Linux. Die wichtigsten Befehle sind sehr ähnlich.
Tipp: Jeder Code lässt sich mit „Kopieren“ übernehmen. Zum Lernen ist es aber besser, ihn selbst abzutippen – so üben Sie Schreibweise und Umgang mit dem Terminal.
Teil 1: Orientieren
1. PowerShell öffnen
Drücken Sie die Windows-Taste, tippen Sie „PowerShell“ und öffnen Sie Windows PowerShell (oder das Terminal unter Windows 11).
2. Wo bin ich? – pwd
pwd („print working directory“) zeigt den Pfad des Ordners, in dem Sie gerade sind.
pwd
3. Was ist hier? – ls -Force
ls -Force listet alle Dateien und Ordner auf – auch versteckte. Ohne Zusatz zeigt ls nur die sichtbaren.
ls -Force
4. Ordner wechseln – cd
Mit cd wechseln Sie in einen Ordner, cd .. geht eine Ebene zurück, cd ~ springt in Ihren Benutzerordner.
cd Downloads
cd ..
cd ~
Tipp – Tab-Taste: Tippen Sie die ersten Buchstaben eines Ordners und drücken Sie Tab – der Name wird automatisch ergänzt. Das spart Zeit und vermeidet Tippfehler.
Teil 2: Ordner und Dateien verwalten
| Befehl | Wirkung |
|---|
mkdir oop26 | Neuen Ordner oop26 anlegen |
New-Item test.txt | Leere Datei anlegen |
cp test.txt kopie.txt | Datei kopieren |
mv test.txt neu.txt | Datei umbenennen (oder verschieben) |
rm neu.txt | Datei löschen – ohne Papierkorb! |
Achtung bei rm: Gelöschte Dateien landen nicht im Papierkorb. Prüfen Sie vorher mit pwd, wo Sie sind.
Keine Leerzeichen in Ordnernamen: Namen wie „1. Semester“ führen in der Kommandozeile zu Fehlern, weil das Leerzeichen als Trennzeichen gilt. Besser: 1_semester oder oop26.
Aufgabe · Ihren Kursordner anlegen
- Wechseln Sie in den Ordner, in dem Sie Ihre Studiensachen speichern (z. B.
cd Documents). - Legen Sie dort den Ordner
oop26 an und wechseln Sie hinein. - Legen Sie darin die Ordner
uebungen, hausaufgaben und schwerpunkt an. - Erstellen Sie die Datei
test.txt, benennen Sie sie in uebung0.txt um und kopieren Sie sie in den Ordner uebungen. - Löschen Sie
uebung0.txt aus oop26 und prüfen Sie mit ls, ob alles stimmt.
Lösung anzeigen
cd ~
cd Documents
mkdir oop26
cd oop26
mkdir uebungen
mkdir hausaufgaben
mkdir schwerpunkt
New-Item test.txt
mv test.txt uebung0.txt
cp uebung0.txt uebungen
rm uebung0.txt
ls
Ihr Benutzerordner kann anders heißen (z. B. Dokumente) – entscheidend ist die Struktur darunter.
Weiter: Übung 1 – Python installieren →
Exercise 0 – Command line (Windows)
Goal of this exercise
You learn the most important command-line commands (PowerShell) and use them to create your course folder. You will need this in every session to run Python programs.
Why the command line?
In the PowerShell you control the computer with typed commands instead of the mouse. In this course you use it to
- go to the folder with your Python files,
- run programs, e.g.
python hello.py, - install packages such as Pygame later on.
Terms: PowerShell (and the older CMD) exist on Windows, the Terminal on macOS and Linux. The most important commands are very similar.
Tip: every code block can be copied with “Copy”. For learning, it is better to type it yourself – that is how you practise syntax and using the terminal.
Part 1: Finding your way
1. Open the PowerShell
Press the Windows key, type “PowerShell” and open Windows PowerShell (or Terminal on Windows 11).
2. Where am I? – pwd
pwd (“print working directory”) shows the path of the folder you are currently in.
pwd
3. What is here? – ls -Force
ls -Force lists all files and folders – including hidden ones. Plain ls shows only the visible ones.
ls -Force
4. Change folder – cd
Use cd to move into a folder, cd .. goes up one level, cd ~ jumps to your home folder.
cd Downloads
cd ..
cd ~
Tip – Tab key: type the first letters of a folder and press Tab – the name is completed automatically. That saves time and avoids typos.
Part 2: Managing folders and files
| Command | Effect |
|---|
mkdir oop26 | Create a new folder oop26 |
New-Item test.txt | Create an empty file |
cp test.txt kopie.txt | Copy a file |
mv test.txt neu.txt | Rename (or move) a file |
rm neu.txt | Delete a file – no recycle bin! |
Careful with rm: deleted files do not go to the recycle bin. Check with pwd where you are first.
No spaces in folder names: names like “1st semester” cause errors on the command line because the space counts as a separator. Better: 1_semester or oop26.
Task · Create your course folder
- Go to the folder where you keep your study files (e.g.
cd Documents). - Create the folder
oop26 there and move into it. - Inside it, create the folders
uebungen, hausaufgaben and schwerpunkt. - Create the file
test.txt, rename it to uebung0.txt and copy it into the folder uebungen. - Delete
uebung0.txt from oop26 and check with ls that everything is right.
Show solution
cd ~
cd Documents
mkdir oop26
cd oop26
mkdir uebungen
mkdir hausaufgaben
mkdir schwerpunkt
New-Item test.txt
mv test.txt uebung0.txt
cp uebung0.txt uebungen
rm uebung0.txt
ls
Your folder may have a different name (e.g. Dokumente) – what matters is the structure below it.
Next: Exercise 1 – Install Python →