learninfra · Linux · Networking · Kubernetes · System Design · AI Infrastructure · Exam blueprints · Drills

Files & the Filesystem

One tree, rooted at /. Learn to move around it, read a listing, and see what a file name really points at.

An interactive Linux lesson: 25 steps, about 35 minutes, on a live simulation in your browser.

It is your first day and you have been given an account on a server called web01. There is no desktop and nothing to click. There is a line of text ending in $, waiting. That line is the prompt: a program called the shell (here, bash) telling you it is ready for a command.

Read it left to right: alice@web01:~$. alice is the user you are logged in as. web01 is the machine. ~ is the directory you are standing in. $ says you are an ordinary user; for root, the administrator, it would be #.

What you will learn

  1. A prompt and a place

    • The prompt: The prompt answers three questions before you type anything: who am I, on which machine, in which directory.
    • Two commands: ls and cat
  2. One tree

    • One tree, rooted at /: Linux has exactly one tree. It starts at /, and every file on the machine has a path from there.
    • What lives where: /etc is configuration, /home is people, /var is data that grows, /usr is installed software, /tmp is scratch.
    • Change directory, then ask again: A path starting with / is absolute and means the same thing from anywhere. Any other path is relative and starts from where you are standing.
    • Three shortcuts: . .. and ~
  3. Reading a listing

    • ls -l, column by column: The first character of an ls -l line is the type: - is a file, d is a directory, l is a symbolic link.
    • ls -a: what ls was hiding
  4. Make, copy, move, delete

    • Make a directory and a file
    • Copy and move: cp makes a new, separate file. mv changes where a file's name lives and leaves the file itself alone.
    • Break it: rm has no undo: rm does not move a file anywhere. The name is gone at once, and nothing on the machine offers to bring it back.
    • Drill: remove a directory
  5. What a name really is

    • A name points at an inode: A directory is a table of names and inode numbers. The inode is the file; a name is one entry that refers to it.
    • A second name: the hard link: A hard link is a second name for the same inode. There is no original and no copy, only a link count.
    • Delete one of the two names: rm removes a name. The data is freed only when the last name is gone and the link count reaches zero.
    • A signpost: the symbolic link: A symbolic link stores a path, not an inode. Every time it is used, that path is looked up afresh.
    • Break it: a dangling link
    • Drill: repair the link
  6. Everything is a file

    • /proc: files that are not on any disk: /proc is the kernel answering questions in the shape of files. Nothing in it is stored; every read is computed.
    • /dev: devices as files: Disks, devices, kernel state and ordinary data all show up as paths, so the same few commands work on all of them.
    • Finding things: find, which, file
  7. Filesystems in the tree

    • Mounts: filesystems grafted in: A mount grafts another filesystem onto a directory of the one tree. Paths look the same on both sides of the join.
    • A hard link across a mount: Hard links stay inside one filesystem and cannot dangle. Symlinks cross anything, including mounts, and can break.
  8. Recap & playground

    • Cheat sheet
    • Playground