Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 95 ยท Getting Started

The Linux Filesystem

Understand the Linux directory tree - /, /etc, /usr, /var, /home, /tmp, /proc and /dev - absolute and relative paths, hidden files and why everything is a file.

On Windows every disk has a letter: C:, D:, and so on. Linux has no drive letters. There is one tree of directories that starts at a single root called /, and every disk, USB stick, network share and even the kernel's internal data shows up somewhere inside that tree. Once you know the standard places in it, you can find your way around any Linux machine you have never seen before.

This lesson explains the layout of the tree, the difference between absolute and relative paths, the special names ., .. and ~, hidden files and case sensitivity, and the idea that everything is a file. Use it as a map for the rest of the course. The next lesson, Navigating: pwd, cd and ls, teaches the commands for moving through the tree.

One tree, starting at /

Everything lives below the root directory /. A path such as /home/ada/notes.txt reads from left to right: start at the root, go into home, then ada, then the file notes.txt. Directory names are separated by forward slashes, never backslashes.

TEXT
/
โ”œโ”€โ”€ bin      essential commands (often a link to /usr/bin)
โ”œโ”€โ”€ etc      system-wide configuration, plain text files
โ”œโ”€โ”€ home     one directory per user: /home/ada, /home/grace
โ”œโ”€โ”€ root     the home directory of the administrator
โ”œโ”€โ”€ usr      installed programs, libraries, documentation
โ”‚   โ”œโ”€โ”€ bin    most commands
โ”‚   โ”œโ”€โ”€ lib    libraries
โ”‚   โ””โ”€โ”€ share  data that programs share
โ”œโ”€โ”€ var      data that changes: logs, caches, mail queues, databases
โ”‚   โ””โ”€โ”€ log
โ”œโ”€โ”€ tmp      temporary files, may be cleared on reboot
โ”œโ”€โ”€ dev      device files (disks, terminals, /dev/null)
โ”œโ”€โ”€ proc     live information about the kernel and processes
โ””โ”€โ”€ mnt, media   places where extra disks are attached

This arrangement is described by the Filesystem Hierarchy Standard (FHS), which most distributions follow, so /etc always means configuration and /var/log always means logs. The main directories, in short:

Directory What you find there
/bin, /usr/bin Programs everyone can run: ls, cp, grep, bash
/sbin, /usr/sbin Programs mostly for administrators
/etc Configuration files (passwd, hosts, fstab, os-release)
/home Personal files of the regular users
/root The administrator's own home (not under /home)
/var Variable data: /var/log, /var/lib, /var/cache, /var/tmp
/tmp Scratch space for short-lived files
/usr The bulk of installed software; "Unix System Resources"
/opt Optional, self-contained third-party packages
/dev Device nodes such as /dev/null and /dev/sda
/proc, /sys Virtual files exposing the kernel and hardware
/mnt, /media Mount points for extra disks

Let's check which of these exist in our sandbox. It is a small, stripped-down system, so a few standard directories are missing, which is also a useful reminder that real machines differ.

Bash Which standard directories exist here?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

The sandbox has the directories programs need to run (/bin, /etc, /usr, /tmp, /dev, /proc) but not user data such as /home or /var. On a normal server all of them exist.

Absolute and relative paths

A path is either absolute or relative:

  • An absolute path starts with / and means the same thing wherever you are: /etc/hosts.
  • A relative path does not start with / and is interpreted from the current working directory: notes.txt or docs/index.html.

Every running program, including your shell, has a current directory. Relative paths are shorter, but they mean different things in different places. Scripts that need to be safe usually use absolute paths or build them from a known base.

Three special names exist in every directory:

Name Meaning
. The current directory itself
.. The parent directory (one level up)
~ Your home directory (the shell expands it before running the command)

At the root, .. points to / itself, because there is nothing above it.

Bash Absolute and relative paths

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

${PWD##*/} is a Bash trick that strips everything up to the last slash from the current directory, leaving just the final name; we use it because the full absolute path of the sandbox varies. All three cat commands print the same line, since readme.md, ./readme.md and ../docs/readme.md (up to project, then back down into docs) point to the same file. Going cd .. moves one level up each time. You will see how cd and ls work in detail in the next lesson.

The tilde ~ stands for your home directory, which the shell stores in the HOME variable. In a normal login it is /home/yourname; in our sandbox it is a hidden folder inside the temporary directory, and echo ~ prints it as the relative path .home.

Bash Home directory and the tilde

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

The last two lines show a classic surprise: ~ is replaced by the shell only when it is unquoted at the beginning of a word. In double quotes it stays a literal tilde. Remember this when you build paths in scripts, and write "$HOME/notes" instead of "~/notes".

Hidden files and case sensitivity

A file or directory whose name starts with a dot is hidden: ls and the usual wildcards skip it unless you ask. Dot-files are how programs store per-user settings, like ~/.bashrc for Bash or ~/.gitconfig for Git. There is no special hiding attribute; it is purely a naming convention.

Names are case sensitive, so Report.txt, report.txt and REPORT.TXT can sit side by side in one directory (unlike on default Windows and macOS setups). File names can contain nearly any character except / and the null byte, including spaces and even newlines; this freedom is why careful quoting matters in scripts. Good habit: lowercase letters, digits, dashes and underscores, and no spaces.

Bash Hidden files and case sensitivity

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Plain ls leaves out .hidden.txt, and with -a you see it along with . and ... The three differently cased report files coexist; ls sorts upper-case before lower-case here because the sandbox sets LC_ALL=C (the C locale sorts by byte value), whereas your own locale may mix them.

Everything is a file

Linux presents many things through the filesystem so that the same tools work on all of them: ordinary files, directories, devices, running processes and kernel settings. Some special files worth meeting:

  • /dev/null swallows everything written to it and always reads as empty. It is the "black hole" for output you do not want.
  • /dev/zero produces an endless stream of zero bytes.
  • /proc is a virtual directory. Nothing in it is stored on a disk; the kernel generates the content when you read it. /proc/self always points to the process that is reading it, which is useful for scripts that inspect themselves.
  • /etc/passwd is a plain text list of accounts, one per line, with colon-separated fields.
Bash Special files: /dev and /proc

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

wc -c < /dev/null prints 0: reading the black hole gives no bytes. od shows the four zero bytes as 00 00 00 00. /proc/version starts with Linux, and /proc/self/status has one Name: line describing the reading process. The last line prints the root entry from /etc/passwd, whose fields are user name, password placeholder, user ID, group ID, comment, home directory and login shell. You will learn more in Users, Groups and sudo and Processes.

Mounting is how extra disks join the tree. A second disk is "mounted" on an existing empty directory such as /mnt/backup, and from then on that directory shows the disk's contents. The tree looks seamless even if it spans many disks, which is why df (see Disk Usage) lists every mounted filesystem separately.

Where to look when something is missing

A few reliable rules save a lot of searching:

  • Configuration for system services: /etc. Per-user configuration: dot-files in your home directory.
  • Logs: /var/log, and on modern systems journalctl (Disks, Mounts, Logs).
  • The program itself: command -v name or type name (Getting Help).
  • Temporary data that should not survive: /tmp (use mktemp in scripts).
  • Software you installed by hand: /usr/local or /opt.

Check your understanding

Quick check ยท 6 questions

of 6 answered You scored / 6 ยท perfect!

  1. 1. What is the top of the Linux directory tree called?

    There is a single tree that starts at /. ~ is your home directory, and /root is the administrator's home, not the top.
  2. 2. Which one is an absolute path?

    An absolute path starts with / and does not depend on the current directory. The others are relative.
  3. 3. Where would you normally look for system-wide configuration files?

    /etc holds configuration. /proc is live kernel data, /tmp is scratch space and /dev holds device files.
  4. 4. What does echo "~" print?

    The shell expands ~ only when it is unquoted at the start of a word. In double quotes it stays a plain character.
  5. 5. Which statement about /proc is true?

    Files in /proc are created on demand by the kernel to describe processes and the system; nothing is stored on disk.
  6. 6. Can Notes.txt and notes.txt exist in the same directory?

    Linux filesystems normally treat the two names as different files.

Summary

  • Linux has one directory tree starting at /; extra disks are mounted into it, and there are no drive letters.
  • The FHS gives each directory a role: /etc configuration, /usr software, /var changing data, /home user files, /tmp scratch space, /dev devices, /proc kernel information.
  • Absolute paths start with /; relative paths start from the current directory. . is here, .. is the parent, ~ is your home (unquoted).
  • Names starting with a dot are hidden by convention, and names are case sensitive.
  • Many things are files: /dev/null discards data, /proc is generated by the kernel, and /etc files are plain text.

Next: Navigating: pwd, cd and ls