Files
OBIJupyterHub/jupyterhub_volumes/course/unix_exercises_bash.ipynb

1560 lines
26 KiB
Plaintext
Raw Normal View History

2025-11-16 14:27:42 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"# Unix Essentials — Bash Practice Notebook\n",
"\n",
2025-11-16 14:27:42 +01:00
"This notebook contains 50 short exercises grouped in 5 series.\n",
"Each exercise has a hidden solution for self-assessment."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"## Series 1 Path Manipulation\n",
"\n",
"Focus: `pwd`, `cd`, `mkdir`, `.`, `..`, relative and absolute paths."
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.1 Show current directory"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"pwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.2 Create a directory named `work`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mkdir work"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.3 Change to the `work` directory"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cd work"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.4 Create two subdirectories `data` and `logs`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mkdir data logs"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.5 Move back to the parent directory"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cd .."
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.6 Create nested directories `project/src` in one command"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mkdir -p project/src"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.7 Display the absolute path"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"pwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.8 List all including hidden ones"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ls -a"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.9 Create directory using absolute path `/tmp/test1`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mkdir /tmp/test1"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 1.10 Remove directory `/tmp/test1`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"rmdir /tmp/test1"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"## Series 2 File Manipulation\n",
"\n",
"Focus: `rm`, `rm -rf`, `rmdir`, `cp`, `mv`."
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.1 Create an empty file `a.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"touch a.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.2 Copy `a.txt` to `b.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cp a.txt b.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.3 Rename `b.txt` to `c.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mv b.txt c.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.4 Move `c.txt` to `/tmp/`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mv c.txt /tmp/"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.5 Create a folder `tempdir`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mkdir tempdir"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.6 Create files `x.txt`, `y.txt` in it"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"touch tempdir/x.txt tempdir/y.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.7 Remove `y.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"rm tempdir/y.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.8 Remove non-empty folder `tempdir` recursively"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"rm -rf tempdir"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.9 Create and remove empty folder `delete_me`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"mkdir delete_me && rmdir delete_me"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 2.10 Create file with text using echo"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"echo 'hello world' > greeting.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"## Series 3 Redirections and Pipes\n",
"\n",
"Focus: Redirect input/output, combine with pipes."
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.1 Save `ls` output to file"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ls > list.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.2 Append date to `list.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"date >> list.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.3 View first 5 lines of `list.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"head -5 list.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.4 Count lines using pipe"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cat list.txt | wc -l"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.5 Redirect errors to `errors.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ls /fake 2> errors.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.6 Redirect both output and errors"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ls /fake > all.txt 2>&1"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.7 Use pipe to sort `list.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cat list.txt | sort"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.8 Combine commands with `| grep`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ls /etc | grep conf"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.9 Use input redirection `<` to count words"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"wc -w < list.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 3.10 Chain three commands"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cat list.txt | sort | uniq"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"## Series 4 Viewing Results\n",
"\n",
"Focus: `head`, `tail`, `cat`, `grep`, `less`."
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.1 Display first 10 lines of `/etc/passwd`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"head /etc/passwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.2 Show last 5 lines of `/etc/passwd`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"tail -5 /etc/passwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.3 View complete file `/etc/hostname`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cat /etc/hostname"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.4 Search for 'root' in `/etc/passwd`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"grep root /etc/passwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.5 Count matches of 'bash' in `/etc/passwd`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"grep -c bash /etc/passwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.6 Show line numbers with `grep`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"grep -n bash /etc/passwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.7 Invert match to exclude 'bash'"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"grep -v bash /etc/passwd"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.8 Use `tail` to see the 5 last lines of `/etc/services`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"tail -5 /etc/services"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.9 Concatenate multiple small files"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cat a.txt greeting.txt > merged.txt"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 4.10 Show sorted unique words from `list.txt`"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"cat list.txt | tr ' ' '\\n' | sort | uniq"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"## Series 5 Process Management\n",
"\n",
"Focus: `ps`, `kill`, `ctrl-c`, `ctrl-z`, `top`."
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.1 List processes"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ps"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.2 Show detailed process tree"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"ps aux"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.3 Find your shell PID"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"echo $$"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.4 Launch sleep in background"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"sleep 60 &"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.5 List background jobs"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"jobs"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.6 Bring job to foreground"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"fg"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.7 Stop a process by PID"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"kill <PID>"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2025-11-16 14:56:03 +01:00
"### Exercise 5.8 Force kill a process"
2025-11-16 14:27:42 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your work here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
2025-11-16 14:56:03 +01:00
"outputs_hidden": true,
"source_hidden": true
2025-11-16 14:27:42 +01:00
}
},
"outputs": [],
"source": [
2025-11-16 14:56:03 +01:00
"# Solution\n",
"kill -9 <PID>"
2025-11-16 14:27:42 +01:00
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 5
2025-11-16 14:56:03 +01:00
}