{ "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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:38.453457Z", "iopub.status.busy": "2026-05-20T17:56:38.452977Z", "iopub.status.idle": "2026-05-20T17:56:38.587064Z", "shell.execute_reply": "2026-05-20T17:56:38.585611Z", "shell.execute_reply.started": "2026-05-20T17:56:38.453423Z" } }, "outputs": [], "source": [ "!mkdir tests" ] }, { "cell_type": "code", "execution_count": 2, "id": "bigger-check", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:56:38.588572Z", "iopub.status.busy": "2026-05-20T17:56:38.588376Z", "iopub.status.idle": "2026-05-20T17:56:38.716534Z", "shell.execute_reply": "2026-05-20T17:56:38.715226Z", "shell.execute_reply.started": "2026-05-20T17:56:38.588548Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "create-delete.ipynb length.txt\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 sorted-length.txt\n", "index.rst \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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:38.719198Z", "iopub.status.busy": "2026-05-20T17:56:38.718623Z", "iopub.status.idle": "2026-05-20T17:56:38.852450Z", "shell.execute_reply": "2026-05-20T17:56:38.851016Z", "shell.execute_reply.started": "2026-05-20T17:56:38.719143Z" } }, "outputs": [], "source": [ "!touch tests/test_file.txt" ] }, { "cell_type": "code", "execution_count": 4, "id": "leading-malpractice", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:56:38.854773Z", "iopub.status.busy": "2026-05-20T17:56:38.854458Z", "iopub.status.idle": "2026-05-20T17:56:38.980760Z", "shell.execute_reply": "2026-05-20T17:56:38.980134Z", "shell.execute_reply.started": "2026-05-20T17:56:38.854745Z" } }, "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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:38.981751Z", "iopub.status.busy": "2026-05-20T17:56:38.981553Z", "iopub.status.idle": "2026-05-20T17:56:39.118390Z", "shell.execute_reply": "2026-05-20T17:56:39.116922Z", "shell.execute_reply.started": "2026-05-20T17:56:38.981701Z" } }, "outputs": [], "source": [ "!mv tests/test_file.txt tests/test_file.py" ] }, { "cell_type": "code", "execution_count": 6, "id": "joined-notebook", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.122773Z", "iopub.status.busy": "2026-05-20T17:56:39.122513Z", "iopub.status.idle": "2026-05-20T17:56:39.251686Z", "shell.execute_reply": "2026-05-20T17:56:39.250498Z", "shell.execute_reply.started": "2026-05-20T17:56:39.122750Z" } }, "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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.254118Z", "iopub.status.busy": "2026-05-20T17:56:39.253400Z", "iopub.status.idle": "2026-05-20T17:56:39.384847Z", "shell.execute_reply": "2026-05-20T17:56:39.384168Z", "shell.execute_reply.started": "2026-05-20T17:56:39.254065Z" } }, "outputs": [], "source": [ "!cp tests/test_file.py tests/test_file2.py" ] }, { "cell_type": "code", "execution_count": 8, "id": "lined-moldova", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.386523Z", "iopub.status.busy": "2026-05-20T17:56:39.385928Z", "iopub.status.idle": "2026-05-20T17:56:39.512786Z", "shell.execute_reply": "2026-05-20T17:56:39.512169Z", "shell.execute_reply.started": "2026-05-20T17:56:39.386462Z" } }, "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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.514711Z", "iopub.status.busy": "2026-05-20T17:56:39.514031Z", "iopub.status.idle": "2026-05-20T17:56:39.648357Z", "shell.execute_reply": "2026-05-20T17:56:39.646903Z", "shell.execute_reply.started": "2026-05-20T17:56:39.514656Z" } }, "outputs": [], "source": [ "!cp -r tests tests.bak" ] }, { "cell_type": "code", "execution_count": 10, "id": "subject-samuel", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.650873Z", "iopub.status.busy": "2026-05-20T17:56:39.650332Z", "iopub.status.idle": "2026-05-20T17:56:39.783324Z", "shell.execute_reply": "2026-05-20T17:56:39.782030Z", "shell.execute_reply.started": "2026-05-20T17:56:39.650815Z" } }, "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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.785855Z", "iopub.status.busy": "2026-05-20T17:56:39.785261Z", "iopub.status.idle": "2026-05-20T17:56:39.916678Z", "shell.execute_reply": "2026-05-20T17:56:39.915331Z", "shell.execute_reply.started": "2026-05-20T17:56:39.785802Z" } }, "outputs": [], "source": [ "!rm -r tests tests.bak" ] }, { "cell_type": "code", "execution_count": 12, "id": "fatty-spelling", "metadata": { "execution": { "iopub.execute_input": "2026-05-20T17:56:39.918548Z", "iopub.status.busy": "2026-05-20T17:56:39.918102Z", "iopub.status.idle": "2026-05-20T17:56:40.046657Z", "shell.execute_reply": "2026-05-20T17:56:40.045411Z", "shell.execute_reply.started": "2026-05-20T17:56:39.918492Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "create-delete.ipynb length.txt\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 sorted-length.txt\n", "index.rst\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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:40.049148Z", "iopub.status.busy": "2026-05-20T17:56:40.048341Z", "iopub.status.idle": "2026-05-20T17:56:40.366162Z", "shell.execute_reply": "2026-05-20T17:56:40.364837Z", "shell.execute_reply.started": "2026-05-20T17:56:40.049091Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--2026-05-20 19:56:40-- https://dvc.org/deb/dvc.list\n", "Resolving dvc.org (dvc.org)... 199.16.172.237, 199.16.173.60\n", "Connecting to dvc.org (dvc.org)|199.16.172.237|:443... connected.\n", "HTTP request sent, awaiting response... 303 See Other\n", "Location: https://downloads.dvc.org/deb/dvc.list [following]\n", "--2026-05-20 19:56:40-- https://downloads.dvc.org/deb/dvc.list\n", "Resolving downloads.dvc.org (downloads.dvc.org)... 2600:9000:225b:a200:1a:8fd1:7400:93a1, 2600:9000:225b:400:1a:8fd1:7400:93a1, 2600:9000:225b:9000:1a:8fd1:7400:93a1, ...\n", "Connecting to downloads.dvc.org (downloads.dvc.org)|2600:9000:225b:a200:1a:8fd1:7400:93a1|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 51 [binary/octet-stream]\n", "Saving to: ‘dvc.list’\n", "\n", "dvc.list 100%[===================>] 51 --.-KB/s in 0s \n", "\n", "2026-05-20 19:56:40 (1,39 MB/s) - ‘dvc.list’ saved [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": { "execution": { "iopub.execute_input": "2026-05-20T17:56:40.368664Z", "iopub.status.busy": "2026-05-20T17:56:40.368115Z", "iopub.status.idle": "2026-05-20T17:56:40.555748Z", "shell.execute_reply": "2026-05-20T17:56:40.555146Z", "shell.execute_reply.started": "2026-05-20T17:56:40.368612Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\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 }