Files
OBIJupyterHub/jupyterhub_volumes/course/unix.ipynb
2025-10-31 19:56:10 +01:00

143 lines
2.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"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 Jupyters 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
}