Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Talking to the computer in sentences
Instead of clicking icons, you can type short commands to a program called the shell: “list these files”, “find every line that says ERROR”, “count them”. The magic is that small commands can be chained with a pipe |, like an assembly line where each worker does one job and hands the result to the next. On the big computers scientists use, and on most robots, this is how almost everything is done.
$ cat flight.log | grep ERROR | cut -d , -f 3 | sort | uniq -c | sort -rn | head -n 2
2026-11-30T10:00,INFO,startup 2026-11-30T10:01,ERROR,imu_timeout 2026-11-30T10:02,WARN,battery_low 2026-11-30T10:03,ERROR,imu_timeout 2026-11-30T10:04,ERROR,gps_lost 2026-11-30T10:05,INFO,ok 2026-11-30T10:06,ERROR,imu_timeout 2026-11-30T10:07,ERROR,gps_lost 2026-11-30T10:08,ERROR,star_tracker
2026-11-30T10:01,ERROR,imu_timeout 2026-11-30T10:03,ERROR,imu_timeout 2026-11-30T10:04,ERROR,gps_lost 2026-11-30T10:06,ERROR,imu_timeout 2026-11-30T10:07,ERROR,gps_lost 2026-11-30T10:08,ERROR,star_tracker
imu_timeout imu_timeout gps_lost imu_timeout gps_lost star_tracker
gps_lost gps_lost imu_timeout imu_timeout imu_timeout star_tracker
2 gps_lost
3 imu_timeout
1 star_tracker 3 imu_timeout
2 gps_lost
1 star_tracker 3 imu_timeout
2 gps_lostCluster jobs, flight-software builds, log triage after a test campaign and data transfers from ground stations are all driven from the shell. A five-command pipeline can answer “which fault occurred most often in last night’s 40 GB of telemetry logs?” in seconds, on the machine where the data already lives.
- 1. What does the pipe | do?
- 2. The shell is…
- 3. In the demo, why is sort needed before uniq -c?
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Everyday commands
| Task | Command |
|---|---|
| where am I, what’s here | pwd, ls -lh, tree -L 2 |
| move around, create, copy, move, remove | cd, mkdir -p, cp -r, mv, rm (no undo!) |
| look at files | cat, less, head -n 20, tail -f run.log |
| search | grep -rn "ERROR" logs/, find . -name "*.h5" -mtime -1 |
| text processing | cut, sort, uniq -c, wc -l, sed, awk |
| disk usage | df -h (file systems), du -sh * (directories) |
| help | man grep, grep --help |
Redirection and exit codes
cmd > out.txt writes stdout to a file (overwriting), >> appends, 2> err.txt redirects stderr, 2>&1 merges stderr into stdout, < in.txt reads stdin from a file. Every command returns an exit status: 0 means success, anything else failure; $? holds the last one. a && b runs b only if a succeeded, a || b only if it failed.
- 1. Which redirect appends instead of overwriting?
- 2. An exit status of 0 means…
- 3. du -sh * shows…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.How the shell reads a line
Before running anything, the shell transforms the line in a fixed order:
- Splitting into words on whitespace, respecting quotes:
'single quotes'are completely literal;"double quotes"keep spaces but still expand$VAR; a backslash escapes one character. - Expansion:
$VARand${VAR}, command substitution$(cmd), arithmetic$((1+2)). - Word splitting of unquoted expansion results (the reason to write
"$file", not$file, for names with spaces). - Globbing: unquoted
*,?,[abc]are replaced by matching file names, sorted; if nothing matches, bash leaves the pattern as is. - Pipes and redirections are set up, and each command runs as a separate process.
Robust scripts
#!/usr/bin/env bash
set -euo pipefail # stop on errors, on unset variables, and on failures inside pipes
IFS=$'\n\t'
out_dir="${1:?usage: $0 OUT_DIR}" # required argument with an error message
mkdir -p "$out_dir"
for f in data/*.csv; do # quote every expansion
python process.py "$f" > "$out_dir/$(basename "$f" .csv).json"
done
find logs -name "*.log" -print0 | xargs -0 grep -l "FATAL" || trueRun shellcheck on every script; it catches unquoted variables, useless cats and many subtle bugs. Once logic grows past a screen, switch to Python.
- 1. echo '$HOME' prints…
- 2. Why write "$file" with quotes?
- 3. set -o pipefail makes a pipeline fail when…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.The file-system model
Everything is one tree rooted at /; disks, network shares and parallel file systems are mounted at directories. A file’s data and metadata (owner, mode, size, timestamps, block pointers) live in an inode; a directory is a table from names to inode numbers. A hard link is a second name for the same inode; a symbolic link is a small file containing a path (it can dangle). Permissions are rwx for user, group and others (chmod 750, chown); for directories x means “may enter”. Space is allocated in blocks (typically 4 KiB), so a 1-byte file still occupies a block.
Storage on a cluster
- Home (
$HOME): small, backed up, often slow (NFS). Code and configs. - Project/work: shared, quota-limited, sometimes backed up.
- Scratch: large, fast parallel file system (Lustre, GPFS/Spectrum Scale, BeeGFS), purged after some days, not backed up. Job data.
- Node-local SSD (
$TMPDIR): fastest, wiped after the job.
Parallel file systems stream huge files at many GB/s, but every open, stat and close is a round trip to a metadata server. Millions of small files therefore overload them; pack datasets into shards (tar/WebDataset, HDF5, Zarr with large chunks, C7) and stage to local SSD.
- 1. A symbolic link stores…
- 2. Where should a job write 2 TB of intermediate files on a cluster?
- 3. Why are millions of small files slow on Lustre?
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Shell and storage, measured
Exercise 1. The tokenizer reproduces shlex.split on quoting cases including 'one two', a\ b and mixed quotes, expands $RUN and ${HOME} but not inside single quotes, and globs *.csv while leaving '*.csv' and non-matching patterns literal. On an 8-line flight log, cat | grep ERROR | cut -d , -f 3 | sort | uniq -c | sort -rn | head -n 2 gives 3 imu_timeout and 2 gps_lost. Without the first sort, uniq merges nothing (8 lines stay 8; with sort there are 5 distinct messages).
Exercise 2: the small-files problem. 200 000 files with lognormal sizes (median 48 KiB, 24.5 GiB in total) under three illustrative storage profiles (per-file metadata cost and streaming bandwidth: NVMe 20 µs and 3 GiB/s, NFS 1.5 ms and 0.5 GiB/s, parallel FS 1 ms and 5 GiB/s):
| Quantity | Value |
|---|---|
| extra space with 4 KiB / 64 KiB / 1 MiB blocks | 1.6% / 29% / 716% |
| tar overhead (512-byte headers and padding) | 0.58% |
| read time, parallel FS: file by file → 99 shards of 256 MiB | 205 s → 5.0 s |
| read time, NFS | 349 s → 49 s |
| read time, local NVMe | 12.2 s → 8.2 s |
| file size for half the streaming bandwidth (t_meta·bw) | 63 KiB / 786 KiB / 5.1 MiB |
On the parallel file system, metadata accounts for 98% of the file-by-file time; sharding removes it (41× faster), while the local SSD barely notices. A file system with 1 MiB blocks would need 8.2× the space for this dataset. These profiles are assumptions for illustration: measure your own system with a timed read loop.
The shell in AI, robotics and aerospace
- Cluster workflows: job scripts, data staging to node-local SSD, log triage with grep and awk.
- Robots: ROS 2 launch and bag tools are shell commands; field debugging happens over SSH in a terminal (C4.2).
- Ground segments: cron-driven shell scripts move telemetry files, verify checksums (
sha256sum -c) and archive them. - ML datasets: WebDataset tar shards and sequential reads exist because of the small-files problem.
References
- W. Shotts (2019). The Linux Command Line, 2nd ed. No Starch Press.
- IEEE Std 1003.1 (POSIX), Shell Command Language (pubs.opengroup.org).
- GNU Bash Reference Manual (gnu.org/software/bash/manual).
- M. K. McKusick, G. V. Neville-Neil, R. N. M. Watson (2014). The Design and Implementation of the FreeBSD Operating System, 2nd ed., file-system chapters. Addison-Wesley.
- P. Braam (2019). “The Lustre storage architecture.” arXiv:1903.01955.