Skip to content

Week 02 - Exercises

Exercise 1: layout tour (/etc)

# List the first 10 entries in the /etc directory.
ls /etc | head -10

# head /etc/passwd displays the first 10 lines of /etc/passwd, a system file containing basic account information, such as usernames and assigned user IDs.
head /etc/passwd

# `head -n 20 /etc/passwd` would instead show the first 20 lines.
head -n 20 /etc/passwd

# Count all .conf files under /etc, ignoring permission errors
find /etc -name "*.conf" 2>/dev/null | wc -l

# Count all .conf files under /etc, ignoring permission errors, and show the first 10 matches
find /etc -name "*.conf" 2>/dev/null | head -n 10

Exercise 2: tricky file names

# Read the content of the file called -
cat < -

# Read the content of the file called --spaces in this filename--
cat < --spaces in this filename--
# => -bash: --spaces: No such file or directory
# Without quotes the shell splits the name at the spaces, so it redirects from "--spaces" only.

cat < '--spaces in this filename--'
# or
cat -- '--spaces in this filename--'

# Read the content of a hidden file called ...hidden-file
cat < ...hidden-file

# Read the content of the only human-readable file in the folder my-files, ignoring the other files that are binary or empty

file my-files/*
cat my-files/filename

# in one line, find the only human-readable file in the folder my-files and display its content, ignoring the other files that are binary or empty
cat "$(file my-files/* | awk -F': ' '$2 ~ /^ASCII text/ {print $1}')"

Exercise 3: ls in depth

# List all files in the current directory, including hidden files, and show their inode numbers
ls -lai

# List all files in the current directory, including hidden files, and show their inode numbers, sorted by inode number
ls -lai | sort -n

# List both the user's home directory (symbolized by the “~” character) and the /usr directory:
ls ~ /usr

# List entries in the current directory as a detailed, time-sorted list, from oldest to newest.
ls -lt --reverse

# Counts the number of entries displayed in /usr/bin.
ls /usr/bin | wc -l

# Display details in long format for entries in three system directories
ls -l /bin /lib /sbin

# List all files in the user's home directory, including hidden files, in long format
ls -la ~

# List the details of the /tmp directory itself, not its contents
ls -ld /tmp

Exercise 4: du (disk usage) in depth

# du stands for disk usage. It reports how much disk space files and directories take up, and it walks the directory tree recursively.

# Show the disk usage of ~/src directory inside the user's home directory, in human-readable format (e.g., KB, MB, GB):
du -sh ~/src

# sizes of everything in /var, hiding permission errors
du -sh /var/* 2>/dev/null

# 10 biggest files and directories under here
du -ah | sort -rh | head

Exercise 5: df (disk free) in depth

# df stands for disk free. It reports free and used space per mounted filesystem, not per directory like du.

# Show all mounted filesystems with sizes in human-readable format (e.g., KB, MB, GB)
df -h

# Same, and also show the filesystem type (in WSL the Windows drives appear as 9p or drvfs)
df -hT

Exercise 6: find in depth

# Find all files in the current directory & subdirectories exactly 1033 bytes and not executable
find . -type f -size 1033c ! -executable

# Same search, and show the file type of each match (to check which one is human-readable text)
find . -type f -size 1033c ! -executable -exec file {} +

# Same search, and display the contents of each match
find . -type f -size 1033c ! -executable -exec cat {} +

# Same search, display the contents with all spaces and newlines removed, then end with one newline
find . -type f -size 1033c ! -executable -exec cat {} + | tr -d ' \n';  echo

# find all files in the entire filesystem owned by alice, in group devs, and exactly 33 bytes in size, ignoring permission errors
find / -type f -user alice -group devs -size 33c 2>/dev/null

# Same search, and display the contents of each match
find / -type f -user alice -group devs -size 33c -exec cat {} \; 2>/dev/null

Extra find drills

Try each task yourself first; the solutions are at the end of this exercise.

Run this once. It builds a small fake .NET repo in /tmp/find-lab with varied names, sizes, ages, permissions, links and empty directories.

rm -rf /tmp/find-lab && mkdir -p /tmp/find-lab && cd /tmp/find-lab

mkdir -p src/App/bin/Debug src/App/obj src/Lib/bin src/Lib/Models docs/images empty-dir/nested-empty .git/hooks
echo 'class Program {}'        > src/App/Program.cs
echo 'class Startup {}'        > src/App/Startup.cs
echo 'class User {}'           > src/Lib/Models/User.cs
echo 'class ORDER {}'          > src/Lib/Models/ORDER.CS
echo '<Project/>'              > src/App/App.csproj
echo '<Project/>'              > src/Lib/Lib.csproj
echo 'dll'                     > src/App/bin/Debug/App.dll
echo 'cs in bin'               > src/App/bin/Debug/Generated.cs
echo 'cs in bin'               > src/Lib/bin/Lib.cs
echo 'readme'                  > README.md
echo 'readme'                  > docs/readme.md
echo '#!/bin/bash'             > build.sh && chmod 755 build.sh
echo 'secret'                  > secret.txt && chmod 600 secret.txt
echo 'open'                    > open.txt   && chmod 666 open.txt

# size: 5 MB, 20 MB and a 2 KB file
head -c 5M  /dev/urandom > docs/images/small.bin
head -c 20M /dev/urandom > docs/images/big.bin
head -c 2K  /dev/urandom > docs/images/tiny.bin

# links
ln -s src/App/Program.cs link-to-program
ln -s does-not-exist.txt dangling-link

# age: one file 10 days old, one 2 hours old, one 5 minutes old
touch -d '10 days ago'    old.log
touch -d '2 hours ago'    recent.log
touch -d '5 minutes ago'  fresh.log

cd /tmp/find-lab

# Check it worked: How many entries are in /tmp/find-lab.
 `find /tmp/find-lab | wc -l`
# should print a number above 30.
### Part A: name and type
# A1. List every `.cs` file (case-sensitive). How many do you get?
find . -name "*.cs"
# A2. Repeat A1 but also match `ORDER.CS`. What changed, and which flag did it?
find . -iname "*.cs"
# A3. List only directories. Then only symlinks. Then only regular files.
find . -type d
find . -type l
find . -type f
# A4. List the files whose name starts with `read` (any case).
find . -iname "read*"
# A5. Find files that are **not** `.cs` files (`!` or `-not`).
find . -type f -not -iname "*.cs"
# A6. Find `.cs` **or** `.csproj` files in one command (`-o`, with escaped parentheses).
find . \( -name "*.cs" -o -name "*.csproj" \)
# A7. Search only the top two levels (`-maxdepth 2`), then only files at least three levels deep (`-mindepth 3`).
find . -maxdepth 2
find . -mindepth 3 -type f

### Part B: size and time
# B1. Find files larger than 10 MB.
find . -type f -size +10M
# B2. Find files between 1 MB and 10 MB (hint: combine `-size +1M` and `-size -10M`).
find . -type f -size +1M -size -10M
# B3. Find files smaller than 100 bytes that are not empty (`-size -100c`, `-not -empty`).
find . -type f -size -100c -not -empty
# B4. Find files modified in the last 24 hours (`-mtime -1`), then in the last 30 minutes (`-mmin -30`).
find . -type f -mtime -1
find . -type f -mmin -30
# B5. Find files **older** than 7 days (`-mtime +7`).
find . -type f -mtime +7
# B6. Explain why `-mtime +7` does not match a file that is exactly 7.5 days old. (Look up how `find` rounds days.)
find counts whole 24h periods and rounds the age DOWN, so 7.5 days counts as 7, and "+7" means "more than 7", i.e. 8 or more. Use -mmin for exact limits.
# B7. Show size and date for every match (`-printf '%s bytes  %TY-%Tm-%Td  %p\n'`).
find . -type f -printf '%s bytes  %TY-%Tm-%Td  %p\n'

### Part C: owner and permissions
# C1. Find files owned by you (`-user "$USER"`). Then files **not** owned by you.
find . -user "$USER"
find . -not -user "$USER"
# C2. Find files with exactly mode 600 (`-perm 600`).
find . -type f -perm 600
# C3. Find files that are executable by the owner (`-perm -u+x`).
find . -type f -perm -u+x
# C4. Find files that anyone can write to (`-perm -o+w`).
find . -type f -perm -o+w
# C5. Explain the difference between `-perm 644`, `-perm -644` and `-perm /644`.
explain the difference between `-perm 644`, `-perm -644` and `-perm /644`.
# 644   = exactly these bits and nothing else
# -644  = ALL of these bits set (others may also be set)
# /644  = ANY of these bits set
# C6. Find files in `/etc` that are readable by nobody except root: `-perm 600 -user root`. Hide errors.
find ./etc -type f -perm 600 -user root 2>/dev/null

### Part D: actions
# D1. Print a detailed listing of each `.csproj` file with `-ls`.
find . -name "*.csproj" -ls
# D2. Run `wc -l` on every `.cs` file with `-exec ... {} \;`. Count how many times `wc` is started. Count the total number of lines in all `.cs` per file
find . -name "*.cs" -exec wc -l {} \;
# D3. Do the same with `-exec ... {} +`. What is different in the output and in the number of `wc` runs? => it adds a total line at the end, and runs `wc` fewer times.
find . -name "*.cs" -exec wc -l {} +
# D4. Use `-exec grep -l "class" {} +` to list files that contain the word `class`.
find . -type f -exec grep -l "class" {} +
# D5. Delete the `.log` files in two steps: first list them, then add `-delete`. Why must `-delete` come **last**?
find . -name "*.log"
find . -name "*.log" -delete
# D6. Use `-ok rm {} \;` on `open.txt` to see the confirmation prompt. Answer `n`.
find . -name open.txt -ok rm {} \;
# D7. Handle odd file names safely: `find . -print0 | xargs -0 ls -ld`. Why is `-print0` needed?
find . -print0 | xargs -0 ls -ld

### Part E: pruning

# E1. Find all `.cs` files, **including** the ones in `bin` (baseline). Count them.
find . -name "*.cs" | wc -l
# E2. Find all `.cs` files, skipping every `bin` directory with `-prune`. Count again.
find . -name bin -prune -o -name "*.cs" -print | wc -l
# E3. Skip both `bin` and `obj` (`\( -name bin -o -name obj \) -prune -o ... -print`).
find . \( -name bin -o -name obj \) -prune -o -name "*.cs" -print
# E4. Skip `.git` and list the rest of the tree. Why is `-print` needed at the end?
find . -name .git -prune -o -print
# E5. Explain why `find . -name bin -prune -o -name "*.cs"` without `-print` still prints the `bin` directories.
with no action, find adds an implicit -print around the WHOLE expression:
( -name bin -prune -o -name "*.cs" ) -print, so the pruned bin directory itself is printed too.

### Part F: hiding errors
# F1. Run `find / -name "*.conf" | head -3`. Note the "Permission denied" lines.
find / -name "*.conf" | head -3
# F2. Run it again with `2>/dev/null`.
find / -name "*.conf" 2>/dev/null | head -3
# F3. Put `2>/dev/null` in the middle of the command (before the pipe or before the path). What happens? Explain why redirections belong at the end of the command they apply to.
=> redirections belong at the end of the command they apply to. `2>/dev/null` only redirects stderr of the command it is attached to. After the pipe it would belong to `head`, not to `find`, so the errors would still appear.
# F4. Count the errors instead of hiding them: `find / -name "*.conf" 2>&1 >/dev/null | wc -l`. Explain the order of `2>&1` and `>/dev/null`.

### Part G: challenges on your real projects
# G1. The 10 largest files (biggest first as `<size in bytes> <path>`) under `~/src`, with sizes (use `-type f`, `-printf` or `-exec du`, then `sort -rh | head`).
find ~/src -type f -printf '%s %p\n' 2>/dev/null | sort -rn | head -10
# explanation
# => `find ~/src -type f` walks `~/src` and keeps regular files only (no directories or symlinks).# => `-printf '%s %p\n'` prints each match as its size in bytes (`%s`), a space, its path (`%p`) and a newline (`\n`) instead of just the path.
# => `2>/dev/null` hides errors such as "Permission denied" (stderr only); it applies to `find`, so it sits right after it, before the pipe.
# => `sort -rn` sorts numerically (`-n`) in reverse (`-r`), so the largest size is first. Plain `sort` would compare as text and put `9` after `10`.
# => `head -10` keeps only the first 10 lines.

# G2. All `.csproj` files modified this week, ignoring `bin` and `obj`.
find ~/src \( -name bin -o -name obj \) -prune -o -name "*.csproj" -mtime -7 -print
# G3. All empty directories in this repo (`-type d -empty`), and all empty files.
find . -type d -empty
find . -type f -empty
# G4. All `bin` and `obj` directories under `~/src` and their total size (hint: `-type d \( -name bin -o -name obj \) -prune`, then `du -shc`). Do not delete them.
find ~/src -type d \( -name bin -o -name obj \) -prune -print0 | du -shc --files0-from=-
# G5. Every file in `~/src` containing the text `TODO`, using `find` + `grep` (then compare with `grep -r --include=*.cs TODO ~/src`).
find ~/src -type f -name "*.cs" -exec grep -l "TODO" {} +
# G6. Find duplicate-sized files in `docs/images`, sorted by size (`-printf '%s %p\n' | sort -n`).
find docs/images -type f -printf '%s %p\n' | sort -n

Exercise 7: following logs with tail -f

Parts A to F use a fake log writer, so you can drill the commands without .NET. Parts G and H use a real ASP.NET Core app.

Setup A: a fake log writer

mkdir -p ~/tmp/tail-lab && cd ~/tmp/tail-lab
: > app.log

# Writes one line per second in the background: a mix of INFO, WARN and ERROR
(
  i=0
  while true; do
    i=$((i+1))
    case $((i % 5)) in
      0) level=ERROR ;;
      1|3) level=WARN ;;
      *) level=INFO ;;
    esac
    echo "$(date +%T) $level request $i path=/api/items/$((RANDOM % 20))" >> app.log
    sleep 1
  done
) &
echo "writer PID: $!"

Stop it when you are done with Parts A to F: kill <PID> (or kill %1).

Part A: the basics

# A1. Show the last 10 lines of `app.log`, then the last 3. What is the default?
tail app.log        # the default is 10 lines
tail -n 3 app.log
# A2. Follow the file live with `tail -f`. Stop with Ctrl-C. Does Ctrl-C stop the writer too? Why not?
# => Ctrl+C only signals the foreground process group of your terminal. Which process that is depends on where you pressed it.

# A3. Follow the file but start with the last 20 lines (`tail -n 20 -f`).
tail -n 20 -f app.log
# A4. Show everything from line 5 onwards (`tail -n +5`), no following.
tail -n +5 app.log
# A5. Follow only new lines, with no history (`tail -n 0 -f`).
tail -n 0 -f app.log
# A6. Follow two files at once (`tail -f app.log /etc/hostname`). What does tail print between files?
tail -f app.log /etc/hostname
# A7. Compare `head -n 3`, `tail -n 3` and `sed -n '4,6p'` on the same file.
head -n 3 app.log
tail -n 3 app.log
sed -n '4,6p' app.log

Part B: filtering a live stream with grep

# B1. Follow only the ERROR lines: `tail -f app.log | grep ERROR`.
tail -f app.log | grep ERROR
# B2. Follow ERROR **or** WARN lines (`grep -E`).
tail -f app.log | grep -E 'ERROR|WARN'
# B3. Follow everything except INFO (`grep -v`).
tail -f app.log | grep -v INFO
# B4. Add a second filter after the first: `tail -f app.log | grep ERROR | grep 'items/1'`. Does it print anything quickly? Why does it feel stuck?

# Yes, it feels stuck because the first grep writes into a pipe, so it buffers (about 4 KB) and flushes late. The second grep waits for input, so it seems stuck until the first grep flushes its buffer.
tail -f app.log | grep ERROR | grep 'items/1'

# B5. Fix B4 use `grep --line-buffered` on the first grep to flush every line immediately.
tail -f app.log | grep --line-buffered ERROR | grep 'items/1'

# B6. Highlight instead of filter: `tail -f app.log | grep --color=always -E 'ERROR|$'` (the empty `$` alternative keeps every line).
tail -f app.log | grep --color=always -E 'ERROR|$'

# B7. Search a file for the word "millionth" (case-insensitive) and show the matching lines with line numbers.
grep -in 'millionth' data.txt

# B8. Show only the word after "millionth" in the matching lines (hint: `awk`).
awk '{for (i=1; i<NF; i++) if ($i=="millionth") {print $(i+1); exit}}' data.txt

Part C: when the file changes underneath you

# C1. Terminal 1: `tail -f app.log`. Terminal 2: `: > app.log` (truncate). Note the message `tail` prints and what happens to the following.
# C2. Terminal 1:
tail -f app.log
# Terminal 2:
mv app.log app.log.1 && touch app.log
# Does `tail -f` follow the new file? Which one does it show?

# Explanation: tail -f is short for --follow=descriptor.
# It holds the file descriptor of the file it opened. If someone renames or deletes the file, tail keeps watching the old file (now renamed or unlinked), and nothing new ever shows up.

# C3. Repeat C2 with `tail -F app.log`. What changed, and what do the extra messages say?
tail -F app.log
# output terminal:
# tail: 'app.log' has become inaccessible: No such file or directory
# tail: 'app.log' has appeared;  following new file

# Explanation: tail -F is short for --follow=name --retry.
# It keeps checking the path:
# - If the file is rotated (app.log is renamed to app.log.1 and a new app.log is created), it reopens the new app.log and continues.
# - If the file doesn't exist yet or is deleted, it keeps retrying until the file appears, instead of exiting with an error.

# C4. Delete the file while `tail -f` runs (`rm app.log`).
# The writer is still running and recreates the file with `>>`.
# Does `tail -f` see the new file? no
# Does `tail -F`? yes, tail -F notices the file reappear and follows it.

Part D: less +F

# D1. Run `less +F app.log`. Compare with `tail -f`.

# Explanation: less +F is like tail -f, but you can scroll up and search while the file is still growing.

# + tells less to run a command on startup, and F is the "forward forever" command. So less +F app.log opens the file and immediately starts following it. You can also press F inside a normal less session to start following.

# What it does differently from tail -f
# - Interactive: Press Ctrl+C to stop following. This does not quit less. You drop into normal mode, where you can scroll (↑ ↓, PgUp, g, G), search (/ERROR, n), and so on.
# - Resume: Press F again to jump to the end and follow again. Quit with q.
# - Full history: You can scroll back through the whole file, not just the last N lines that were on the screen.
# - Follows the descriptor, like -f: It does not handle rotation or deletion the way -F does. Use less +F with --follow-name (less --follow-name +F app.log) if you want it to reopen a replaced file.
# D2. Press Ctrl-C to stop following, scroll up with the arrow keys and search with `/ERROR`.
# D3. Press `F` to resume following, then `q` to quit.
# D4. When is `less +F` better than `tail -f`? When is it worse?
# => Better for reading around while the log still grows (scroll back, search, then resume).
# => Worse for piping, scripting and filtering: less is interactive, so you cannot pipe its output into grep or awk.

Part E: stdout, stderr and redirection

# E1. Run this and note what ends up in the file and what on your screen:
( echo "to stdout"; echo "to stderr" >&2 ) > out.log
# E2. Redirect both streams into one file: `> out.log 2>&1`. Then swap the order: `2>&1 > out.log`. What differs?
( echo "to stdout"; echo "to stderr" >&2 ) > out.log 2>&1
( echo "to stdout"; echo "to stderr" >&2 ) 2>&1 > out.log
# => The first form puts both streams in the file. In the second, stderr goes to the screen and only stdout goes to the file.
# => Redirections are read left to right: 2>&1 copies where stdout points AT THAT MOMENT.

# E3. Append instead of overwrite (`>>`). Why do you want `>>` for a log you are following with `tail -f`?
( echo one ) >> out.log
# => `>` truncates the file (tail -f prints "file truncated" and starts again); `>>` keeps the content and adds to the end.

# E4. Send the same output to the screen **and** a file with `tee`: `command 2>&1 | tee out.log`.
ls /nonexistent /tmp 2>&1 | tee out.log

# E5. Run `ls /nonexistent /tmp > both.log 2>&1` and read `both.log`. Where does the error line appear?
ls /nonexistent /tmp > both.log 2>&1; cat both.log
# => The error line comes first: ls reports the missing argument before it lists the directories.

Part F: the log as a tool

# F1. Count the lines per level with:
awk '{print $2}' app.log | sort | uniq -c

# step by step:
# 1. awk '{print $2}' app.log reads each line, splits it on whitespace, and prints only the 2nd field ($1 is the first, $2 the second, and so on). The output is one value per line.
# 2. sort puts identical values next to each other. This step is required for the next one.
# 3. uniq -c collapses adjacent identical lines into one and puts the count in front.

# note: awk is named after its three creators, using the first letter of each surname:
# - Aho (Alfred Aho)
# - Weinberger (Peter Weinberger)
# - Kernighan (Brian Kernighan)
# They wrote it at Bell Labs in 1977. It is a small language for processing text line by line, splitting each line into fields ($1, $2, …) and running actions on lines that match a pattern.

# F2. Show the last 5 ERROR lines:
grep ERROR app.log | tail -n 5

# F3. Count the requests per second with:
cut -c1-8 app.log | uniq -c | tail

# F4. Follow the file and count the ERROR lines so far with a watcher in a second terminal:
watch -n 1 'grep -c ERROR ~/tmp/tail-lab/app.log'

# F5. Use `tail -f app.log | head -n 5`. Why does `tail` exit by itself after 5 lines?
tail -f app.log | head -n 5

Setup B: a real ASP.NET Core app

Run this once. It creates a minimal web API and adds one log line of our own.

cd ~/src
dotnet new webapi -o tail-demo --no-https
cd tail-demo

Open Program.cs and add this line above app.Run();:

app.MapGet("/hello/{name}", (string name, ILogger<Program> logger) =>
{
    logger.LogInformation("Hello requested for {Name}", name);
    return $"Hello {name}";
});

Run it so that it writes to a log file. The port is fixed, so you can use the same curl commands:

# Terminal 1:
dotnet run --no-launch-profile -- --urls http://localhost:5099 \
  --Logging:LogLevel:Microsoft.AspNetCore=Information > /tmp/app.log 2>&1

The command line after -- is passed to the app. The second option turns on request logging, which is hidden by default.

Part G: follow the real app

# G1. Terminal 2:
tail -f /tmp/app.log
#Terminal 3:
curl -i localhost:5099/weatherforecast

# curl output (terminal 3):
# [{"date":"2026-12-02","temperatureC":19,"summary":"Chilly","temperatureF":66}, {"date":"2026-12-06","temperatureC":44,"summary":"Balmy","temperatureF":111}]

# What lines appear in terminal 2?

# G2.
curl -i localhost:5099/nothing-here
# Which status code and which log line do you see? 404

# G3.
curl localhost:5099/hello/Linux
# find your own `Hello requested for Linux` line in the log.

# G4. Follow the log and print only lines with `Hello` or a 404 (`grep --line-buffered -E 'Hello|404'`).
tail -f /tmp/app.log | grep --line-buffered -E 'Hello|404'
# G5. Send 20 requests in a loop:
for i in $(seq 1 20); do curl -s localhost:5099/hello/user$i > /dev/null; done
# Watch the log scroll.

# G6. Find the line with `Now listening on:` using `grep -n`.
grep -n 'Now listening on:' /tmp/app.log

# G7. Stop the app (Ctrl-C in terminal 1). What does the last part of the log say about shutdown?
# => "Application is shutting down..."

# G8. Run it **without** `> /tmp/app.log 2>&1`. Where does the output go, and why can't you follow it from another terminal?
# => It goes to the terminal of terminal 1 (its stdout is the tty), and another terminal cannot attach to it.
# => That is why services log to a file or to journald.

# G9. Run it again with only `> /tmp/app.log` (no `2>&1`) and trigger an unhandled error, for example by starting a second copy on the same port. Which output went to the file and which stayed on your screen? Explain what this means for production logs.
# => The .NET console logger writes to stdout, so its `fail: ... address already in use` message goes to the file.
# => What stays on the screen is stderr: the unhandled-exception / crash output (stack trace, abort message).
# => So the log file alone can miss the crash details. Redirect both streams (`2>&1`), or let systemd/journald collect them.

Part H: the file is gone, but the process is not

Run the app with > /tmp/app.log 2>&1 again, then:

# H1. Find the app's PID: `pgrep -f tail-demo` (note: there may be two entries, `dotnet run` and the app itself).
pgrep -f tail-demo
# => The app process is the child of `dotnet run`.

# H2. `ls -l /proc/<pid>/fd`. Which descriptors are 0, 1 and 2, and where do 1 and 2 point?
ls -l /proc/<pid>/fd
# => 0 points to /dev/null or the terminal; 1 and 2 both point to /tmp/app.log.

# H3. `rm /tmp/app.log` while the app is running. Send a few requests. Does the app still work?
rm /tmp/app.log
curl -s localhost:5099/hello/Linux
# => Yes. The app writes to its already-open file descriptor, so it does not notice that the name is gone.

# H4. `ls -l /proc/<pid>/fd` again. What does the `(deleted)` suffix mean?
ls -l /proc/<pid>/fd
# => The name is gone, but the process still holds the inode open.

# H5. Read the "deleted" log back with `cat /proc/<pid>/fd/1`. Why does this work?
cat /proc/<pid>/fd/1
# => The kernel keeps the inode alive as long as any process holds it open.

# H6. Does `df` show the space as free? Why is a big log that was deleted while the process is running a classic reason for a full disk?
df -h /tmp
# => No. df still counts the space, because the inode is not released until the process closes it.
# => Find such files with: ls -l /proc/*/fd 2>/dev/null | grep deleted

# H7. Recover: restart the app with `> /tmp/app.log 2>&1`, or truncate instead of deleting (`: > /tmp/app.log`). Which is safe to do on a running process?
: > /tmp/app.log
# => Truncating is safe: the inode and descriptor stay, only the content goes.
# => Deleting needs an app restart (or a signal that makes it reopen its logs) to free the space.

Clean up when you are finished:

kill %1 2>/dev/null      # the fake writer, if it is still running in this shell
rm -rf ~/tmp/tail-lab /tmp/app.log