diff --git a/module6.ipynb b/module6.ipynb index 0bcd648..68d5023 100644 --- a/module6.ipynb +++ b/module6.ipynb @@ -7,12 +7,101 @@ "# Interacting with the Command Line Shell" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Basic Linux Commands" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "mkdir mynewdir\n", + "cd mynewdir/\n", + "/mynewdir$ pwd\n", + "/mynewdir$ cp ../spider.txt .\n", + "/mynewdir$ touch myfile.txt\n", + "/mynewdir$ ls -l \n", + "#Output:\n", + "#-rw-rw-r-- 1 user user 0 Mai 22 14:22 myfile.txt\n", + "#-rw-rw-r-- 1 user user 192 Mai 22 14:18 spider.txt\n", + "/mynewdir$ ls -la\n", + "#Output:\n", + "#total 12\n", + "#drwxr-xr-x 2 user user 4096 Mai 22 14:17 .\n", + "#drwxr-xr-x 56 user user 12288 Mai 22 14:17 ..\n", + "#-rw-rw-r-- 1 user user 0 Mai 22 14:22 myfile.txt\n", + "#-rw-rw-r-- 1 user user 192 Mai 22 14:18 spider.txt\n", + "/mynewdir$ mv myfile.txt emptyfile.txt\n", + "/mynewdir$ cp spider.txt yetanotherfile.txt\n", + "/mynewdir$ ls -l\n", + "#Output:\n", + "#total 8\n", + "#-rw-rw-r-- 1 user user 0 Mai 22 14:22 emptyfile.txt\n", + "#-rw-rw-r-- 1 user user 192 Mai 22 14:18 spider.txt\n", + "#-rw-rw-r-- 1 user user 192 Mai 22 14:23 yetanotherfile.txt\n", + "/mynewdir$ rm *\n", + "/mynewdir$ ls -l\n", + "#total 0\n", + "/mynewdir$ cd ..\n", + "rmdir mynewdir/\n", + "ls mynewdir\n", + "#ls: cannot access 'mynewdir': No such file or directory\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Redirecting streams" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cat stdout_example.py \n", + "#!/usr/bin/env python3\n", + "print(\"Don't mind me, just a bit of text here...\")\n", + "./stdout_example.py \n", + "#Output: Don't mind me, just a bit of text here...\n", + "./stdout_example.py > new_file.txt\n", + "cat new_file.txt \n", + "#Output: Don't mind me, just a bit of text here...\n", + "./stdout_example.py >> new_file.txt\n", + "cat new_file.txt \n", + "#Output: Don't mind me, just a bit of text here...\n", + " #Don't mind me, just a bit of text here...\n", + "cat streams_err.py \n", + "#!/usr/bin/env python3\n", + "\n", + "data = input(\"This will come from STDIN: \")\n", + "print(\"Now we write it to STDOUT: \" + data)\n", + "raise ValueError(\"Now we generate an error to STDERR\")\n", + "./streams_err.py < new_file.txt\n", + "#This will come from STDIN: Now we write it to STDOUT: Don't mind #me, just a bit of text here...\n", + "#Traceback (most recent call last):\n", + " #File \"./streams_err.py\", line 5, in \n", + " #raise ValueError(\"Now we generate an error to STDERR\")\n", + "#ValueError: Now we generate an error to STDERR\n", + "./streams_err.py < new_file.txt 2> error_file.txt\n", + "#This will come from STDIN: Now we write it to STDOUT: Don't mind #me, just a bit of text here...\n", + "cat error_file.txt \n", + "#Traceback (most recent call last):\n", + " #File \"./streams_err.py\", line 5, in \n", + " #raise ValueError(\"Now we generate an error to STDERR\")\n", + "#ValueError: Now we generate an error to STDERR\n", + "echo \"These are the contents of the file\" > myamazingfile.txt\n", + "cat myamazingfile.txt \n", + "#These are the contents of the file\n" + ] } ], "metadata": {