Curious Pandas

Everything is a file

One tree, starting at /. Learn to walk it with absolute and relative paths, find the files ls hides, and meet the file that swallows everything you write to it.

14 min+30 XP for finishing

Windows gives every drive a letter: C:, D:. Linux has no letters. It has one tree, and everything hangs from a single root written /. Your files, the machine’s settings, even the hardware: all of it has a place somewhere under /.

Learn that tree and you can find your way around any Linux machine, whether it’s your laptop, a server or the container a cluster is running for you.

Visual guideOne tree, one root
One tree, one rootThe root directory / contains home and etc. home contains panda, the home directory of the user panda, which holds notes.txt. etc holds the machine's settings, such as the file hostname. The absolute path of notes.txt is /home/panda/notes.txt./the roothome/one folder per userpanda/your home: ~notes.txt/home/panda/notes.txtetc/settingshostname/etc/hostnameOne tree, one rootThe root directory / contains home and etc. home contains panda, the home directory of the user panda, which holds notes.txt. etc holds the machine's settings, such as the file hostname. The absolute path of notes.txt is /home/panda/notes.txt./the roothome/one folder per userpanda/your home: ~notes.txt/home/panda/notes.txtetc/settingshostname/etc/hostname
  1. Everything starts at /, the root. There is exactly one.
  2. Each user gets a folder under /home. Yours is /home/panda, and ~ is shorthand for it.
  3. A full path from the root is absolute: /home/panda/notes.txt means the same file wherever you are standing.
  4. The machine's own settings live under /etc, as ordinary text files you can read with cat.

Where am I, and how do I get there?

Your shell always stands in one directory, the working directory. pwd prints it. Paths come in two kinds:

  • Absolute paths start with / and are read from the root: /etc/hostname. They mean the same thing wherever you are.
  • Relative paths don’t start with / and are read from where you’re standing: from /home/panda, projects/bamboo means /home/panda/projects/bamboo.

Two names are in every directory: . is the directory itself and .. is its parent. So cd .. climbs one level, and ../../notes.txt climbs two and then picks a file.

Your first Linux machinea toy Linux in your browser
You are here

    Check yourself+10 XP

    You are in /home/panda/projects/bamboo. Which path names /home/panda/notes.txt?

    The files ls doesn’t show you

    ls skips any name that starts with a dot. That’s a convention, not a security feature: dot-files are mostly settings (.bashrc configures your shell) that would otherwise clutter every listing. ls -a shows them, along with . and ...

    Check yourself+10 XP

    ls shows nothing, but ls -a lists .env and .git. What happened?

    Why “everything is a file”

    Linux presents far more than documents as files. Devices live under /dev. Running processes appear under /proc, one folder per process ID, with files describing each one. Settings live in /etc. Because they’re all files, the same handful of tools - cat, echo, > - work on every one of them.

    The most famous is /dev/null. Anything written to it is thrown away, and reading it gives you nothing at all. It’s where you send output you don’t want: noisy-command > /dev/null.

    Do it for real · your machine+20 XP bonus

    Everything above ran in your browser. Now try it in a real terminal: any Linux machine, a Mac's Terminal app, or Windows with WSL. Nothing to install beyond that.

    Look at your own machine’s tree, its hidden files and its live process files:

    pwd
    ls -la ~
    cat /etc/hostname
    head -5 /proc/$$/status    # Linux and WSL: your own shell, as a file
    echo "gone" > /dev/null; cat /dev/null

    On a Mac there is no /proc; ps -p $$ shows the same shell instead.

    Self-reported. We can't see your machine, and we don't want to. This is a bonus, never required.

    Sources

    Finished reading?

    Missions and quizzes above earn their own XP. This marks the lesson done.