Working With Files and Directories
Goal
You learn the basics of creating files and directories, linking them, moving them, and bundling them into a backup, and then you solve two incidents that actually happen because of that structure. You confirm with inode numbers how a hard link differs from a symbolic link, and use that difference to explain "the service that reads an old configuration" and "the space that does not come back after a deletion".
Why it matters
On Linux, a file name is not the thing itself but a reference to it. A directory is just a list of (name, inode number) pairs, and the real owner of the data is the inode. Once you know this structure, "why does mv finish instantly even for a 1GB file," "why does free space not shrink after rm," and "why can't a hard link be made to another disk" are all explained at once. Without this structure, you end up memorizing those three as unrelated oddities.
The last two steps are incidents. A service reading the old value after you fixed the configuration, and space staying the same after you deleted a log, are very common in the field, and both happen because nobody checked "what the name points to". If you cover them up with a restart or a copy based only on the symptom, they blow up the same way next time, so you practice picking the cause from the candidates, recording it, and correcting the structure.
Steps
- Create the workspace
/root/workand the/root/work/logs/2026/08directory under it in one go. - Create
/root/work/hello.txtand puthello labhubon its first line. - Copy
/etc/hostnameto/root/work/hostname. The content must be exactly the same as the original. - Under
/root/work/logs/2026/08, create five files,app1.logthroughapp5.log, and then create/root/work/loglist.txtcontaining only the names of those files (no path), one per line. - For
hello.txt, create a hard link/root/work/hello.hardand a symbolic link/root/work/hello.link. - Create
/root/work/draft.txtwith the single linedraft, write its inode number to/root/work/draft.ino, then move it to/root/work/logs/2026/08/draft.txt. The inode number must stay the same after the move. - Bundle the whole
/root/work/logsdirectory into the gzip-compressed tar archive/root/work/backup.tar.gz. - Incident
lb-stale-config: the canonical configuration was changed to v2, but three services cannot read v2. Pick and record the cause for each service, and fix all three places so they follow the canonical file (do not touch the canonical file). - Incident
lb-space-not-freed: app.log was deleted, but the space did not come back. Recover the deleted content, get the space back without restarting the writer, and then record the cause.
Notes
- With
stat -c '%i %h %s' 파일you can see the inode number, link count, and size at once. - The first column of
ls -liis the inode number. Hard links to each other share this value. - Incident tools:
incident listshows the list of incidents, andincident show <이름>(name) shows a ticket again. Raising the same incident again returns it to its original broken state. - The incident report is
/root/incident/<이름>/report.txt(name is the incident name). If there is one cause, writecause: <코드>(code); if there are several targets, write<대상>: <코드>(target: code) one per line, and at the end addevidence: <원인을 보여 준 출력 한 줄>(one line of output that showed the cause, copied as is). Pick the codes from the candidates listed in the step description. - Common mistake 1: in step 4, if you save the output of
findas it is, you get paths such as./logs/2026/08/app1.log. What you need is only the file names. - Common mistake 2: in step 6, if you copy with
cpand then delete the original, the result looks the same but the inode changes. A move does not copy data; it only rewrites the directory entry. - Common mistake 3: in step 9, if you get the space back first (by making the process reopen the file), the deleted content disappears at that moment. Recovering it comes first.
Create the working directory
Create the workspace /root/work and the /root/work/logs/2026/08 directory under it in one go.
The command that creates a directory is mkdir. By default it fails if the parent directory does not exist, but there is an option that creates the intermediate path all at once.
Create your first file
Create /root/work/hello.txt and put hello labhub on its first line.
You can send the output of echo to a file (redirection), or create it directly with vim.
Copy a system file
Copy /etc/hostname to /root/work/hostname. The content must be exactly the same as the original.
cp leaves the original untouched and creates a new file. The copy must have exactly the same content as the original.
Extract a list of log files
Under /root/work/logs/2026/08, create five files, app1.log through app5.log, and then create /root/work/loglist.txt containing only the names of those files (no path), one per line.
This splits into two jobs: creating five files and collecting their names. Tools that find files usually output the full path, so you need a way to keep only the last part (the file name). The finding tool itself has an option that sets the output format, and there is also a separate command that strips just the name from a path.
Hard link and symbolic link
For hello.txt, create a hard link /root/work/hello.hard and a symbolic link /root/work/hello.link.
A hard link attaches one more name to the same inode, while a symbolic link is a separate file that holds a path string. Both are made with the same command, and a single option tells them apart. After creating them, put the inode numbers and link counts of the three names side by side and the difference is obvious.
Move a file: the inode stays the same
Create /root/work/draft.txt with the single line draft, write only the inode number of that file to /root/work/draft.ino, then move it to /root/work/logs/2026/08/draft.txt. Nothing may remain in the original location, and the inode number after the move must match the number you recorded.
Within the same filesystem, a move does not move data; it only changes the directory entry (the name). That is why the inode number stays the same. A copy creates a new inode, so if you copy and then delete the original, the content is the same but the number differs. You can see the inode number with stat's format specifiers or with ls -i.
Back up the log directory
Bundle the whole /root/work/logs directory into the gzip-compressed tar archive /root/work/backup.tar.gz. The grader opens the archive and checks that every .log file currently on disk is in it, with the same content and none missing.
tar is the tool that bundles many files into one, and a single option also applies gzip compression. You give three things as options: create, compress, and the file name. If you use the option that moves the base directory to /root/work, the paths inside the archive become shorter, like logs/…. After bundling, check what is inside with the list option.
Incident: the configuration changed, but three services read the old value
Running incident lb-stale-config raises the incident. The canonical file /srv/lbconf/shared/app.conf was changed to version=2, but three services (which read /srv/lbconf/svc-a/app.conf, svc-b/app.conf, and svc-c/app.conf) cannot read v2; you can confirm this with /srv/lbconf/bin/show-versions. Find the cause for each service and fix it so that all three places follow the canonical file. They must keep following it even when the canonical file is saved again by an editor (a new inode), and you must not touch the canonical file itself. In /root/incident/lb-stale-config/report.txt, write three lines, svc-a: <코드>, svc-b: <코드>, and svc-c: <코드>, plus evidence: <관찰한 출력 한 줄> (one line of output you observed). Each service's code is one of the following: symlink-old-target (a link pointing to the old location), dangling-symlink (a link whose target does not exist), stale-copy (a copy taken at deployment time), permission-denied (no permission to read).
Direction: check "are they reading the same file?" by where the name points, not by the content. Do not assume all three have the same cause. Tools: ls -l, readlink, stat, cat. Concretely: if the first character of ls -l is l, it is a link, and what follows -> is the path it points to. Follow that path to see whether it is the canonical file and whether it actually exists. A relative-path link is resolved relative to the directory that contains the link. If the first character is -, it is a regular file; compare its stat inode number with the canonical file's. If you match things up with a hard link or a copy, it reads v2 now, but it splits off again the next time the canonical file is saved as a new inode.
Incident: the log was deleted, but the space did not come back
Running incident lb-space-not-freed raises the incident. The on-call engineer ran rm on /srv/lbweb/log/app.log, but the space did not come back, and that file held payment failure records that must be saved (order=88412). Find the cause, then (1) recover the entire content of the deleted app.log to /root/incident/lb-space-not-freed/app.log.recovered, and (2) get the space back without restarting the lbweb writer (/srv/lbweb/run/writer.pid), making the writer write to /srv/lbweb/log/app.log again (runbook: the writer reopens its log file when it receives SIGHUP). In /root/incident/lb-space-not-freed/report.txt, write cause: <코드> and evidence: <관찰한 출력 한 줄> (one line of output you observed). The code is one of the following: deleted-but-open (a process still has the deleted file open), hardlink-remains (another name for the same inode remains), inode-exhausted (inodes are exhausted), fs-cache-delay (the filesystem is slow to reflect the change).
Direction: data blocks come back only when "there are zero names and zero processes holding the file open". Determine which of the two remains. Order matters too: if you make the process reopen the file before recovering, the content is gone. Tools: ls -l, stat, find, cp, kill. Concretely: files a process has open appear as numbered links under /proc/<PID>/fd/, and a file whose name was deleted has (deleted) appended to the link target. That fd link is a channel you can still read from right now. A file with several names has a link count (%h) of 2 or more in stat, but check separately whether it is the very file that was deleted.