{ "cells": [ { "cell_type": "markdown", "id": "adjustable-sphere", "metadata": {}, "source": [ "# Create, update and delete files and directories" ] }, { "cell_type": "markdown", "id": "continental-feelings", "metadata": {}, "source": [ "Creates a new directory `test` and then checks this with `ls`:" ] }, { "cell_type": "code", "execution_count": 1, "id": "powered-lesbian", "metadata": {}, "outputs": [], "source": [ "!mkdir tests" ] }, { "cell_type": "code", "execution_count": 2, "id": "bigger-check", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "create-delete.ipynb grep-find.ipynb.license\n", "create-delete.ipynb.license index.rst\n", "dvc.list pipes-filters.ipynb\n", "dvc.list.1 pipes-filters.ipynb.license\n", "file-system.ipynb shell-variables.ipynb\n", "file-system.ipynb.license shell-variables.ipynb.license\n", "grep-find.ipynb \u001b[34mtests\u001b[m\u001b[m\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "markdown", "id": "baking-nebraska", "metadata": {}, "source": [ "Then we create the file `test_file.txt` in this directory." ] }, { "cell_type": "code", "execution_count": 3, "id": "white-render", "metadata": {}, "outputs": [], "source": [ "!touch tests/test_file.txt" ] }, { "cell_type": "code", "execution_count": 4, "id": "leading-malpractice", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "test_file.txt\n" ] } ], "source": [ "!ls tests" ] }, { "cell_type": "markdown", "id": "intelligent-richardson", "metadata": {}, "source": [ "Now we change the suffix of the file:" ] }, { "cell_type": "code", "execution_count": 5, "id": "mature-country", "metadata": {}, "outputs": [], "source": [ "!mv tests/test_file.txt tests/test_file.py" ] }, { "cell_type": "code", "execution_count": 6, "id": "joined-notebook", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "test_file.py\n" ] } ], "source": [ "!ls tests" ] }, { "cell_type": "markdown", "id": "conscious-peace", "metadata": {}, "source": [ "Now we make a copy of this file:" ] }, { "cell_type": "code", "execution_count": 7, "id": "figured-value", "metadata": {}, "outputs": [], "source": [ "!cp tests/test_file.py tests/test_file2.py" ] }, { "cell_type": "code", "execution_count": 8, "id": "lined-moldova", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "test_file.py test_file2.py\n" ] } ], "source": [ "!ls tests" ] }, { "cell_type": "markdown", "id": "announced-patch", "metadata": {}, "source": [ "A directory with all the files it contains is also possible recursively with the `-r` option:" ] }, { "cell_type": "code", "execution_count": 9, "id": "persistent-funds", "metadata": {}, "outputs": [], "source": [ "!cp -r tests tests.bak" ] }, { "cell_type": "code", "execution_count": 10, "id": "subject-samuel", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "test_file.py test_file2.py\n" ] } ], "source": [ "!ls tests.bak" ] }, { "cell_type": "markdown", "id": "eight-rainbow", "metadata": {}, "source": [ "Finally, we delete the directories `tests` and `tests.bak` again:" ] }, { "cell_type": "code", "execution_count": 11, "id": "broke-mouth", "metadata": {}, "outputs": [], "source": [ "!rm -r tests tests.bak" ] }, { "cell_type": "code", "execution_count": 12, "id": "fatty-spelling", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "create-delete.ipynb grep-find.ipynb.license\n", "create-delete.ipynb.license index.rst\n", "dvc.list pipes-filters.ipynb\n", "dvc.list.1 pipes-filters.ipynb.license\n", "file-system.ipynb shell-variables.ipynb\n", "file-system.ipynb.license shell-variables.ipynb.license\n", "grep-find.ipynb\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "markdown", "id": "peripheral-timer", "metadata": {}, "source": [ "## Transferring files" ] }, { "cell_type": "markdown", "id": "brazilian-floating", "metadata": {}, "source": [ "### `wget`" ] }, { "cell_type": "code", "execution_count": 13, "id": "thousand-glenn", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--2024-10-28 17:22:50-- https://dvc.org/deb/dvc.list\n", "Auflösen des Hostnamens dvc.org (dvc.org)… 2606:4700:3036::6815:51cd, 172.67.164.76, 104.21.81.205, ...\n", "Verbindungsaufbau zu dvc.org (dvc.org)|2606:4700:3036::6815:51cd|:443 … verbunden.\n", "HTTP-Anforderung gesendet, auf Antwort wird gewartet … 303 See Other\n", "Platz: https://s3-us-east-2.amazonaws.com/dvc-s3-repo/deb/dvc.list [folgend]\n", "--2024-10-28 17:22:51-- https://s3-us-east-2.amazonaws.com/dvc-s3-repo/deb/dvc.list\n", "Auflösen des Hostnamens s3-us-east-2.amazonaws.com (s3-us-east-2.amazonaws.com)… 3.5.130.80, 52.219.92.209, 52.219.106.105, ...\n", "Verbindungsaufbau zu s3-us-east-2.amazonaws.com (s3-us-east-2.amazonaws.com)|3.5.130.80|:443 … verbunden.\n", "HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK\n", "Länge: 51 [binary/octet-stream]\n", "Wird in »dvc.list« gespeichert.\n", "\n", "dvc.list 100%[===================>] 51 --.-KB/s in 0s \n", "\n", "2024-10-28 17:22:51 (1,52 MB/s) - »dvc.list« gespeichert [51/51]\n", "\n" ] } ], "source": [ "!wget https://dvc.org/deb/dvc.list" ] }, { "cell_type": "markdown", "id": "subjective-bandwidth", "metadata": {}, "source": [ "* `-r` recursively crawls other files and directories\n", "* `-np` avoids crawling to parent directories\n", "* `-D` targets only the following domain name\n", "* `-nH` avoids creating a subdirectory for the websites content\n", "* `-m` mirrors with time stamping, time stamping, infinite recursion depth, and preservation of FTP directory settings\n", "* `-q` suppresses the output to the screen" ] }, { "cell_type": "markdown", "id": "pursuant-stephen", "metadata": {}, "source": [ "### `cURL`\n", "\n", "Alternatively, you can use cURL, which supports a much larger range of protocols." ] }, { "cell_type": "code", "execution_count": 14, "id": "royal-wilderness", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", "100 85 100 85 0 0 79 0 0:00:01 0:00:01 --:--:-- 79\n" ] } ], "source": [ "!curl -o dvc.list https://dvc.org/deb/dvc.list" ] } ], "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 }