Working With Files and Directories
Goal
You get hands-on practice with the flow of creating, moving, linking, and bundling files and directories into a backup. In particular, you confirm directly with inode numbers how a hard link differs from a symbolic link.
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.
Steps
- Create the
/root/workdirectory. - 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. - Create the
/root/work/logs/2026/08directory in one go. - 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, then move it to/root/work/logs/2026/08/draft.txt. - Compress and bundle the whole
/root/work/logsdirectory into/root/work/backup.tar.gz.
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. - Common mistake 1: in step 5, 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 7, using
cpleaves the original behind and fails. A move does not copy data; it only rewrites the directory entry.
Create the working directory
Create the /root/work directory.
The command that creates a directory is mkdir. Use the path /root/work exactly as given.
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.
Create nested directories in one go
Create the /root/work/logs/2026/08 directory in one go.
By default, mkdir fails if the parent directory does not exist. There is an option that creates the whole parent path at once.
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.
Use find to locate the .log files, but you need only the file names, not the full paths. Think of -printf or basename.
Hard link and symbolic link
For hello.txt, create a hard link /root/work/hello.hard and a symbolic link /root/work/hello.link.
ln makes a hard link and ln -s makes a symbolic link. Compare the inode number (%i) and the link count (%h) with stat.
Move a file
Create /root/work/draft.txt with the single line draft, then move it to /root/work/logs/2026/08/draft.txt.
This is a move (mv), not a copy (cp). Nothing should remain in the original location.
Back up the log directory
Compress and bundle the whole /root/work/logs directory into /root/work/backup.tar.gz.
You need the combination of options that bundles with tar and compresses with gzip. The whole logs directory must be included.