153 lines
9.1 KiB
HTML
153 lines
9.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Bash 01: Terminal-Navigation & Globbing</title>
|
|
<link rel="stylesheet" href="../../../assets/style.css">
|
|
</head>
|
|
<body>
|
|
<div class="app-layout">
|
|
<div class="app-main">
|
|
<header>
|
|
<div class="header-container">
|
|
<div class="header-badge">🐧 Linux Bash & Cloud DevOps</div>
|
|
<h1>Bash 01: Terminal-Navigation, Dateioperationen & Globbing</h1>
|
|
<p>Beherrsche den Linux-Dateibaum, lerne blitzschnelle Pfad-Navigation und automatisiere Dateioperationen mit Wildcards und Brace Expansion.</p>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container">
|
|
<!-- 1. THEORIE: PFADE & NAVIGATION -->
|
|
<section class="card">
|
|
<h2>🧭 1. Der Unix-Dateibaum & Pfad-Navigation</h2>
|
|
<p>In Unix gibt es keine Laufwerksbuchstaben (wie <code>C:</code> oder <code>D:</code>). Alles entspringt dem Root-Verzeichnis <code>/</code> (Single Root Tree). Wir unterscheiden strikt zwischen absoluten und relativen Pfaden:</p>
|
|
|
|
<pre><code># Wo bin ich?
|
|
pwd # Ausgabe: /home/devops/projects
|
|
|
|
# Relative vs. Absolute Navigation:
|
|
cd /var/log/nginx # Absoluter Pfad: Beginnt immer mit '/'
|
|
cd ../../etc # Relativer Pfad: Zwei Ebenen hoch, dann in 'etc'
|
|
cd ~ # Wechselt ins Home-Verzeichnis (/home/user)
|
|
cd - # Wechselt zum vorherigen Verzeichnis zurück
|
|
|
|
# Detailliertes Listing mit Berechtigungen und Dateigrößen:
|
|
ls -lah # -l: Long Format, -a: Versteckte Dateien, -h: Human-readable (KB/MB)</code></pre>
|
|
</section>
|
|
|
|
<!-- 2. THEORIE: DATEIOPERATIONEN & GLOBBING -->
|
|
<section class="card">
|
|
<h2>📁 2. Dateisystem-Operationen & Mächtiges Globbing</h2>
|
|
<p>Als DevOps-Ingenieur erstellst, kopierst und reorganisierst du Konfigurationsdateien im Sekundentakt. Die Shell bietet hierfür mächtige Werkzeuge:</p>
|
|
|
|
<pre><code># 🎯 1. Verzeichnisse verschachtelt anlegen:
|
|
mkdir -p app/{config,src/{models,views},logs,tests}
|
|
|
|
# 🎯 2. Dateien mit Brace Expansion massenweise erstellen:
|
|
touch app/src/models/{user,order,payment}.py app/config/{dev,staging,prod}.yaml
|
|
|
|
# 🎯 3. Shell-Globbing (Wildcards):
|
|
cp app/config/*.yaml /backup/configs/ # Alle .yaml Dateien kopieren
|
|
mv app/logs/app_2026-??.log /archive/logs/ # Matcht genau 2 Zeichen für den Monat (z.B. 01..12)
|
|
rm -rf /tmp/build_cache/ # Rekursives Löschen ohne Bestätigung</code></pre>
|
|
|
|
<div class="box box-analogie">
|
|
<div class="box-title">🏢 Didaktische Analogie: Das Logistikzentrum des Betriebssystems</div>
|
|
<p><strong>Der Dateibaum:</strong> Stell dir das Dateisystem wie ein riesiges, strukturiertes Hochregallager vor. <code>/</code> ist der Haupteingang. <code>mkdir -p</code> baut dir sofort eine ganze Gasse mit Fachböden auf.</p>
|
|
<p><strong>Globbing (<code>*</code> und <code>{a,b}</code>):</strong> Anstatt jedes Paket einzeln mit der Hand zu scannen, hältst du eine Schablone hoch: <code>*.yaml</code> greift automatisch alle blauen Kisten aus dem Regal, während <code>{dev,prod}</code> mit einem Handgriff zwei vorgefertigte Etiketten druckt!</p>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- 3. CHEAT-SHEET -->
|
|
<section class="card">
|
|
<h2>📑 3. Cheat-Sheet: Navigation & Wildcards</h2>
|
|
<div style="overflow-x: auto;">
|
|
<table style="width: 100%; border-collapse: collapse; font-size: 0.9rem; text-align: left;">
|
|
<thead>
|
|
<tr style="border-bottom: 2px solid var(--border-color); background: var(--bg-subtle);">
|
|
<th style="padding: 10px;">Befehl / Muster</th>
|
|
<th style="padding: 10px;">Beispiel</th>
|
|
<th style="padding: 10px;">Bedeutung & DevOps-Einsatz</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>mkdir -p <pfad></code></td>
|
|
<td style="padding: 10px;"><code>mkdir -p /srv/app/releases</code></td>
|
|
<td style="padding: 10px;">Erstellt Elternverzeichnisse automatisch ohne Fehler</td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>cp -r <src> <dst></code></td>
|
|
<td style="padding: 10px;"><code>cp -r ./templates /etc/nginx/</code></td>
|
|
<td style="padding: 10px;">Kopiert ganze Verzeichnisbäume rekursiv</td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>mv <src> <dst></code></td>
|
|
<td style="padding: 10px;"><code>mv old.env .env.backup</code></td>
|
|
<td style="padding: 10px;">Verschiebt oder benennt Dateien atomar um</td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>rm -rf <pfad></code></td>
|
|
<td style="padding: 10px;"><code>rm -rf ./temp_workspace</code></td>
|
|
<td style="padding: 10px;">Löscht rekursiv und erzwingt Löschen ohne Prompt</td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>*</code> (Wildcard)</td>
|
|
<td style="padding: 10px;"><code>rm -f *.log</code></td>
|
|
<td style="padding: 10px;">Matcht 0 oder beliebig viele Zeichen</td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>?</code> (Single Char)</td>
|
|
<td style="padding: 10px;"><code>ls node_v?.log</code></td>
|
|
<td style="padding: 10px;">Matcht exakt ein einziges Zeichen</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="padding: 10px;"><code>{a,b,c}</code></td>
|
|
<td style="padding: 10px;"><code>touch {app,db}_{1..3}.conf</code></td>
|
|
<td style="padding: 10px;">Brace Expansion zur raschen Permutationserstellung</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- 4. AUFGABEN CHECKLISTE -->
|
|
<section class="card">
|
|
<h2>🎯 Aufgaben & Checkliste in <code>aufgabe.sh</code></h2>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t1">
|
|
<label class="task-label" for="t1"><strong>TODO 1:</strong> <code>erstelle_projektstruktur(basis_dir)</code> mit <code>mkdir -p</code> implementieren (src/components, src/utils, docs/api, backup/logs).</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t2">
|
|
<label class="task-label" for="t2"><strong>TODO 2:</strong> <code>erstelle_testdateien(basis_dir)</code> mit <code>touch</code> und Dateimustern umsetzen.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t3">
|
|
<label class="task-label" for="t3"><strong>TODO 3:</strong> <code>kopiere_konfigurationen(src_dir, backup_dir)</code> mit <code>cp</code> und Globbing (<code>*.yaml</code>, <code>*.log</code>) schreiben.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t4">
|
|
<label class="task-label" for="t4"><strong>TODO 4:</strong> <code>verschiebe_dateien(src_dir, target_dir)</code> für <code>*.md</code> Dokumentationen implementieren.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t5">
|
|
<label class="task-label" for="t5"><strong>TODO 5:</strong> <code>bereinige_temporaere_dateien(basis_dir)</code> mit <code>rm -f</code> und <code>rm -rf</code> fertigstellen.</label>
|
|
</div>
|
|
|
|
<div class="box box-tipp" style="margin-top: 20px;">
|
|
<div class="box-title">💡 DevOps Pro-Tipp: Quoting in Shell-Skripten</div>
|
|
<p>Setze Variablen bei Pfadangaben in Bash-Skripten stets in doppelte Anführungszeichen: <code>"$basis_dir/src/components"</code>. Das verhindert gefürchtete <em>Word Splitting</em> Fehler, falls ein Verzeichnisname einmal Leerzeichen enthält!</p>
|
|
</div>
|
|
|
|
<div style="margin-top: 25px; display: flex; gap: 12px; flex-wrap: wrap;">
|
|
<a href="../../../workspace.html?course=bash&track=track_1_terminal_grundlagen&chapter=01_navigation_dateien_und_globbing" class="btn" style="background: #10b981; color: #fff; font-weight: 700;">💻 In Web-IDE öffnen →</a>
|
|
<a href="../02_streams_pipes_und_redirection/index.html" class="btn btn-secondary">Weiter zu Bash 02 →</a>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|