{ "cells": [ { "cell_type": "markdown", "id": "still-rehabilitation", "metadata": {}, "source": [ "# Navigieren durch Dateien und Verzeichnisse" ] }, { "cell_type": "markdown", "id": "honey-proof", "metadata": {}, "source": [ "Zuerst wollen wir herausfinden, wo wir uns befinden, indem wir den Befehl `pwd` ausführen:" ] }, { "cell_type": "code", "execution_count": 1, "id": "revolutionary-bulletin", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace/ipython/unix-shell\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "markdown", "id": "rotary-married", "metadata": {}, "source": [ "Hier ist die Antwort das iPython-Kapitel des Jupyter-Tutorials in meinem Home-Verzeichnis `/Users/veit`.\n", "\n", "Unter Windows sieht das Home-Verzeichnis aus wie `C:\\Documents and Settings\\veit` oder `C:\\Users\\veit` und unter Linux wie `/home/veit`.\n", "\n", "Um den Inhalt dieses Verzeichnisses zu sehen, können wir `ls` verwenden:" ] }, { "cell_type": "markdown", "id": "cleared-china", "metadata": {}, "source": [ "To see the contents of our this directory, we can use `ls`:" ] }, { "cell_type": "code", "execution_count": 2, "id": "perfect-courtesy", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "create-delete.ipynb index.rst\n", "create-delete.ipynb.license pipes-filters.ipynb\n", "file-system.ipynb pipes-filters.ipynb.license\n", "file-system.ipynb.license shell-variables.ipynb\n", "grep-find.ipynb shell-variables.ipynb.license\n", "grep-find.ipynb.license\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "markdown", "id": "efficient-arkansas", "metadata": {}, "source": [ "* ein nachgestelltes `/` kennzeichnet ein Verzeichnis\n", "* `@` zeigt einen Link an\n", "* `*` steht für eine ausführbare Datei\n", "\n", "Abhängig von euren Standardoptionen kann die Shell auch Farben verwenden, um anzuzeigen, ob ein Eintrag eine Datei oder ein Verzeichnis ist." ] }, { "cell_type": "markdown", "id": "polish-thursday", "metadata": {}, "source": [ "## `ls`-Optionen und Argumente" ] }, { "cell_type": "code", "execution_count": 3, "id": "major-spell", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "debugging.ipynb\n", "debugging.ipynb.license\n", "display.ipynb\n", "display.ipynb.license\n", "examples.ipynb\n", "examples.ipynb.license\n", "extensions.rst\n", "importing.ipynb\n", "importing.ipynb.license\n", "index.rst\n", "magics.ipynb\n", "magics.ipynb.license\n", "\u001b[34mmypackage\u001b[m\u001b[m/\n", "myscript.py\n", "shell.ipynb\n", "shell.ipynb.license\n", "start.rst\n", "\u001b[31mtab-completion-for-anything.png\u001b[m\u001b[m*\n", "tab-completion-for-anything.png.license\n", "\u001b[31mtab-completion-for-modules.png\u001b[m\u001b[m*\n", "tab-completion-for-modules.png.license\n", "\u001b[31mtab-completion-for-objects.png\u001b[m\u001b[m*\n", "tab-completion-for-objects.png.license\n", "\u001b[34munix-shell\u001b[m\u001b[m/\n" ] } ], "source": [ "!ls -F ../" ] }, { "cell_type": "markdown", "id": "numeric-arena", "metadata": {}, "source": [ "`ls` ist der Befehl, mit der Option `-F` und dem Argument `../`.\n", "\n", "* Optionen beginnen entweder mit einem einzelnen Bindestrich (`-`) oder zwei Bindestrichen (`--`) und ändern das Verhalten eines Befehls.\n", "* Argumente sagen dem Befehl, womit er operieren soll.\n", "* Optionen und Argumente werden manchmal auch als Parameter bezeichnet.\n", "* Jeder Teil wird durch Leerzeichen getrennt.\n", "* Auch die Großschreibung ist wichtig, z. B.\n", " * `ls -s` zeigt neben den Namen auch die Größe der Dateien und Verzeichnisse an, während\n", " * `ls -S` die Dateien und Verzeichnisse nach Größe sortiert." ] }, { "cell_type": "code", "execution_count": 4, "id": "imperial-reflection", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total 160\n", "24 create-delete.ipynb 8 index.rst\n", " 8 create-delete.ipynb.license 16 pipes-filters.ipynb\n", "32 file-system.ipynb 8 pipes-filters.ipynb.license\n", " 8 file-system.ipynb.license 16 shell-variables.ipynb\n", "24 grep-find.ipynb 8 shell-variables.ipynb.license\n", " 8 grep-find.ipynb.license\n" ] } ], "source": [ "!ls -s" ] }, { "cell_type": "code", "execution_count": 5, "id": "neutral-invite", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "file-system.ipynb create-delete.ipynb.license\n", "grep-find.ipynb file-system.ipynb.license\n", "create-delete.ipynb grep-find.ipynb.license\n", "pipes-filters.ipynb pipes-filters.ipynb.license\n", "shell-variables.ipynb shell-variables.ipynb.license\n", "index.rst\n" ] } ], "source": [ "!ls -S" ] }, { "cell_type": "markdown", "id": "cognitive-award", "metadata": {}, "source": [ "### Alle Optionen und Argumente anzeigen\n", "\n", "`ls` hat viele weitere Optionen, und mit `man` könnt ihr euch diese anzeigen lassen:" ] }, { "cell_type": "code", "execution_count": 6, "id": "artificial-aspect", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LS(1) General Commands Manual LS(1)\n", "\n", "NAME\n", " ls – list directory contents\n", "\n", "SYNOPSIS\n", " ls [-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%,] [--color=when]\n", " [-D format] [file ...]\n", "\n", "DESCRIPTION\n", " For each operand that names a file of a type other than directory, ls\n", " displays its name as well as any requested, associated information. For\n", " each operand that names a file of type directory, ls displays the names\n", " of files contained within that directory, as well as any requested,\n", " associated information.\n", "\n", " If no operands are given, the contents of the current directory are\n", " displayed. If more than one operand is given, non-directory operands are\n", " displayed first; directory and non-directory operands are sorted\n", " separately and in lexicographical order.\n", "\n", " The following options are available:\n", "\n", " -@ Display extended attribute keys and sizes in long (-l) output.\n", "\n", " -A Include directory entries whose names begin with a dot (‘.’)\n", " except for . and ... Automatically set for the super-user unless\n", " -I is specified.\n", "…" ] } ], "source": [ "!man ls" ] }, { "cell_type": "markdown", "id": "manufactured-momentum", "metadata": {}, "source": [ "### Unzulässige Optionen\n", "\n", "Wenn ihr versucht, eine Option zu verwenden, die nicht unterstützt wird, geben die Befehle normalerweise eine Fehlermeldung aus, z. B. für:" ] }, { "cell_type": "code", "execution_count": 7, "id": "fuzzy-secondary", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ls: invalid option -- z\n", "usage: ls [-@ABCFGHILOPRSTUWXabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]\n" ] } ], "source": [ "!ls -z" ] }, { "cell_type": "markdown", "id": "unavailable-giving", "metadata": {}, "source": [ "### Versteckte Dateien\n", "\n", "Mit der Option `-a` könn ihr alle Dateien anzeigen:" ] }, { "cell_type": "code", "execution_count": 8, "id": "intellectual-sense", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[34m.\u001b[m\u001b[m grep-find.ipynb\n", "\u001b[34m..\u001b[m\u001b[m grep-find.ipynb.license\n", "\u001b[34m.ipynb_checkpoints\u001b[m\u001b[m index.rst\n", "create-delete.ipynb pipes-filters.ipynb\n", "create-delete.ipynb.license pipes-filters.ipynb.license\n", "file-system.ipynb shell-variables.ipynb\n", "file-system.ipynb.license shell-variables.ipynb.license\n" ] } ], "source": [ "!ls -a" ] }, { "cell_type": "markdown", "id": "cultural-ghana", "metadata": {}, "source": [ "Zusätzlich zu den versteckten Verzeichnissen `..` und `.` seht ihr möglicherweise auch ein Verzeichnis namens `.ipynb_checkpoints`. Diese Datei enthält normalerweise Schnappschüsse der Jupyter-Notebooks." ] }, { "cell_type": "markdown", "id": "latin-exclusive", "metadata": {}, "source": [ "## Verzeichnisbaum anzeigen" ] }, { "cell_type": "code", "execution_count": 9, "id": "middle-stomach", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[01;34m.\u001b[0m\n", "├── \u001b[00mcreate-delete.ipynb\u001b[0m\n", "├── \u001b[00mcreate-delete.ipynb.license\u001b[0m\n", "├── \u001b[00mfile-system.ipynb\u001b[0m\n", "├── \u001b[00mfile-system.ipynb.license\u001b[0m\n", "├── \u001b[00mgrep-find.ipynb\u001b[0m\n", "├── \u001b[00mgrep-find.ipynb.license\u001b[0m\n", "├── \u001b[00mindex.rst\u001b[0m\n", "├── \u001b[00mpipes-filters.ipynb\u001b[0m\n", "├── \u001b[00mpipes-filters.ipynb.license\u001b[0m\n", "├── \u001b[00mshell-variables.ipynb\u001b[0m\n", "└── \u001b[00mshell-variables.ipynb.license\u001b[0m\n", "\n", "1 directory, 11 files\n" ] } ], "source": [ "!tree" ] }, { "cell_type": "markdown", "id": "divided-leone", "metadata": {}, "source": [ "## Verzeichnis wechseln\n", "\n", "Auf den ersten Blick mag für manche irritierend wirken, dass sie mit `!cd` nicht in ein anderes Verzeichnis wechseln können." ] }, { "cell_type": "code", "execution_count": 10, "id": "moved-neutral", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace/ipython/unix-shell\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "code", "execution_count": 11, "id": "crude-toronto", "metadata": {}, "outputs": [], "source": [ "!cd .." ] }, { "cell_type": "code", "execution_count": 12, "id": "detailed-canyon", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace/ipython/unix-shell\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "markdown", "id": "textile-eugene", "metadata": {}, "source": [ "Der Grund dafür ist, dass Jupyter eine temporäre Subshell verwendet. Wenn ihr dauerhaft in ein anderes Verzeichnis wechseln wollt, müsst ihr den [magischen Befehl](../magics.ipynb) `%cd` verwenden." ] }, { "cell_type": "code", "execution_count": 13, "id": "liable-afghanistan", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace/ipython\n" ] } ], "source": [ "%cd .." ] }, { "cell_type": "code", "execution_count": 14, "id": "written-camping", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace/ipython\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "markdown", "id": "divine-garbage", "metadata": {}, "source": [ "Mit der Funktion `%automagic` können diese auch ohne das vorangestellte `%`-Zeichen verwendet werden:" ] }, { "cell_type": "code", "execution_count": 17, "id": "lonely-illness", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Automagic is ON, % prefix IS NOT needed for line magics.\n" ] } ], "source": [ "%automagic" ] }, { "cell_type": "code", "execution_count": 18, "id": "mobile-cologne", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace\n" ] } ], "source": [ "cd .." ] }, { "cell_type": "markdown", "id": "enormous-music", "metadata": {}, "source": [ "### Absolute und relative Pfade" ] }, { "cell_type": "code", "execution_count": 19, "id": "younger-pulse", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de/docs/workspace\n" ] } ], "source": [ "cd ." ] }, { "cell_type": "code", "execution_count": 20, "id": "black-thursday", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn/Python4DataScience-de\n" ] } ], "source": [ "cd ../.." ] }, { "cell_type": "code", "execution_count": 21, "id": "protective-plastic", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit/cusy/trn\n" ] } ], "source": [ "cd .." ] }, { "cell_type": "code", "execution_count": 22, "id": "expired-enough", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/\n" ] } ], "source": [ "cd /" ] }, { "cell_type": "code", "execution_count": 23, "id": "tough-anchor", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit\n" ] } ], "source": [ "cd" ] }, { "cell_type": "code", "execution_count": 24, "id": "positive-orchestra", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit\n" ] } ], "source": [ "cd ~" ] }, { "cell_type": "code", "execution_count": 25, "id": "aggressive-hardware", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/veit\n" ] } ], "source": [ "cd /Users/veit" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.13 Kernel", "language": "python", "name": "python313" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.0" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }