Evolution of Unix course
This commit is contained in:
142
jupyterhub_volumes/course/unix.ipynb
Normal file
142
jupyterhub_volumes/course/unix.ipynb
Normal file
@@ -0,0 +1,142 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Unix Essentials — Bash Exercises\n",
|
||||
"\n",
|
||||
"This notebook contains short hands-on Bash exercises.\n",
|
||||
"Each exercise has a hidden solution that can be unfolded when needed."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Exercise 1 – Listing and Filtering Files\n",
|
||||
"\n",
|
||||
"Create three files and list only those whose name ends with `.log`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# your work here\n",
|
||||
"touch report.log notes.txt errors.log\n",
|
||||
"# list files ending with .log"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"jupyter": {
|
||||
"source_hidden": true,
|
||||
"outputs_hidden": true
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Solution\n",
|
||||
"ls *.log"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Exercise 2 – Redirecting Output\n",
|
||||
"\n",
|
||||
"List the `/etc` directory and save the results in a file named `listing.txt`, then display the first five lines of that file."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# your work here\n",
|
||||
"# 1. list /etc\n",
|
||||
"# 2. redirect output to listing.txt\n",
|
||||
"# 3. show first five lines"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"jupyter": {
|
||||
"source_hidden": true,
|
||||
"outputs_hidden": true
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Solution\n",
|
||||
"ls /etc > listing.txt\n",
|
||||
"head -5 listing.txt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Exercise 3 – Using a For Loop\n",
|
||||
"\n",
|
||||
"Write a loop that prints the line count of each `.txt` file in the current directory."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# your work here\n",
|
||||
"# hint: use wc -l"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"jupyter": {
|
||||
"source_hidden": true,
|
||||
"outputs_hidden": true
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Solution\n",
|
||||
"for f in *.txt; do\n",
|
||||
" echo \"$f: $(wc -l < \"$f\") lines\"\n",
|
||||
"done"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"All solutions are hidden by default (`source_hidden: true`). Students can unfold them in Jupyter’s interface to compare with their own answers."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Bash",
|
||||
"language": "bash",
|
||||
"name": "bash"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "bash"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user