The Linux directory tree

Video 103 of 140 in Virtualization Foundations, in the unit “The shell and the filesystem tree”. 3:10, with English and Hindi audio.

Linux organises every file in one tree, with no drive letters. Each folder in that tree has a job, and knowing the jobs tells you where to look for a setting, a log or a program. It also shows why a folder that fills up can hurt the whole server. This article walks through the main folders of a Linux server, the two live views that hold no files, and one simple command that lets you explore the tree yourself.

What you will learn

One tree with no drive letters

Windows gives each disk its own drive letter, such as C. Linux has one tree instead, and it starts at the root directory, written as a single slash. Every other folder lives somewhere inside that root. Each disk is attached at a folder somewhere in the tree.

List the folders at the top of the tree
ls /

Note: The top folders include etc, home, usr, var and tmp.

Where settings, data and users live

Where the system itself lives

The usr folder holds installed programs and the libraries they need. The boot folder holds the kernel and the files the machine needs to start. The dev folder holds device files, so a disk or a terminal can be reached like an ordinary file. The run folder holds small runtime files, such as sockets, which are kept in memory and cleared at each boot.

The proc and sys folders are different. They are live views. Reading proc shows the kernel's current state, and reading sys shows devices and drivers as the kernel sees them. Nothing is stored in either folder.

Why one full folder can hurt the whole server

Many folders share one disk. Imagine the logs in var growing a little every day. The disk fills up, and the stock service on the same server cannot write new data, so it starts to fail. A folder that is only a small part of the tree can still stop the rest of the server.

Note: Keeping logs in the right place, and clearing them on time, is part of the daily work of a Linux administrator.

Try it yourself

You need a terminal on a Linux machine, such as an Ubuntu server you can log in to. You will look at three places in the tree and see how ls names them.

  1. List the top of the tree. The ls command lists a folder, and here you will see the main folders of the server.

    ls /

    What you should see: The top folders appear, such as etc, home, usr, var and tmp.

  2. Ask about a device file. The null device is a file that discards anything written to it.

    ls /dev/null

    What you should see: The shell shows the full name: /dev/null.

  3. Ask about a configuration file, to see how ls shows a name with its full path.

    ls /etc/hostname

    What you should see: The shell shows the full path: /etc/hostname.

Terms

Root directory
The top of the Linux tree, written as a single slash. Every other folder and disk lives inside it.
Mount point
The folder in the tree where a disk is attached, so its files can be reached through that folder.
Live view
A folder, such as proc or sys, that shows the current state of the kernel or devices and stores nothing on disk.

Check yourself

How does Linux attach a second disk, compared with Windows?

Linux attaches each disk at a folder inside the one tree. Windows gives each disk its own drive letter, such as C.

Why can a full var folder stop a service that lives in another folder?

Many folders share one disk. When the var logs fill it, the service cannot write new data, even though its own folder is not full.

Where should you keep a file you do not want to lose?

Not in tmp, because its files may be removed. A user's own files belong in that user's folder under home.

Previous: Absolute and relative paths. Next: Files, hard links and symbolic links.