TT Lab
Get started
Learn Learning paths Courses

Linux Fundamentals

Working With Files and Directories

Continue in TT Lab

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

  1. Create the /root/work directory.
  2. Create /root/work/hello.txt and put hello labhub on its first line.
  3. Copy /etc/hostname to /root/work/hostname. The content must be exactly the same as the original.
  4. Create the /root/work/logs/2026/08 directory in one go.
  5. 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.
  6. For hello.txt, create a hard link /root/work/hello.hard and a symbolic link /root/work/hello.link.
  7. Create /root/work/draft.txt with the single line draft, then move it to /root/work/logs/2026/08/draft.txt.
  8. Compress and bundle the whole /root/work/logs directory into /root/work/backup.tar.gz.

Notes

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.