# Linux filesystem layout explained (/etc, /var, /usr, /home)

> The Linux filesystem is one tree starting at /, and the Filesystem Hierarchy Standard says where config (/etc), variable data and logs (/var), programs (/usr) and user files (/home) belong.

URL: https://levelrail.com/learn/linux/linux-filesystem-layout/
Updated: 2026-11-27

You log in to a new server and need to change a setting, read an error, or find where an app stores its uploads. On Linux, the answer is almost always in one of a dozen directories, and each has a defined job. Learn the jobs once and you can guess where things live on any distribution.

## How it works

Linux has one filesystem tree that starts at `/`, called the root directory. There are no drive letters. A second disk, a USB stick or a network share is attached to a folder in the tree, a step called mounting (covered in [disk usage and mounts](https://levelrail.com/learn/linux/disk-usage-and-mounts/))).

The layout follows the Filesystem Hierarchy Standard (FHS), a document that says which kind of file belongs where. Debian and Ubuntu follow it closely. The idea is a split by purpose: programs in one place, configuration in another, changing data in a third. That split makes backups and permissions easier, because you can back up `/etc` and `/var/lib` without copying the whole system.

To see the top level on your server:

```bash
ls /
```

Expect names such as `bin`, `boot`, `dev`, `etc`, `home`, `lib`, `opt`, `proc`, `root`, `run`, `srv`, `sys`, `tmp`, `usr` and `var`. The exact list differs a little between machines.

## Configuration: /etc

`/etc` holds system-wide configuration for the machine, mostly as plain text you can read and edit. Typical entries:

- `/etc/ssh/sshd_config` for the SSH server.
- `/etc/nginx/` for nginx, if installed.
- `/etc/fstab` for [filesystems mounted at boot](https://levelrail.com/learn/glossary/#fstab)).
- `/etc/passwd`, `/etc/group` and `/etc/sudoers` for accounts and privileges.
- `/etc/systemd/system/` for unit files you write yourself.
- `/etc/hosts` for local name overrides.

Editing here needs root, and a typo can lock you out of SSH or stop a service from starting. Back up a file before you change it, as shown in [read and edit files on Linux](https://levelrail.com/learn/linux/read-and-edit-files-on-linux/)). Per-user config is different: it lives in hidden files such as `~/.bashrc` and `~/.ssh/config` inside the user's home directory.

## Variable data and logs: /var

`/var` holds files that change while the system runs. Two subfolders matter most on a server.

`/var/log` contains text logs such as `syslog`, `auth.log` and per-service folders like `/var/log/nginx/`. Many services on systemd machines also log to the journal, which you read with journalctl. A runaway log in `/var/log` is a common cause of a full disk.

`/var/lib` contains the state of installed programs. PostgreSQL data is in `/var/lib/postgresql`, Docker images and volumes are under `/var/lib/docker`, and apt keeps its package lists in `/var/lib/apt`. Treat this directory as precious: it is the data you would be sad to lose.

Other parts of `/var` include `/var/cache` (data that can be rebuilt), `/var/spool` (queued jobs such as cron and mail) and `/var/www`, which some web server packages use as a default web root.

## Programs and libraries: /usr, /bin, /lib

`/usr` is where most installed software lives. `/usr/bin` holds commands, `/usr/sbin` holds admin commands, `/usr/lib` holds libraries, and `/usr/share` holds architecture-independent data such as docs and man pages. `/usr/local` is reserved for software you install by hand, so a package upgrade never overwrites it.

On current Ubuntu and Debian, `/bin`, `/sbin` and `/lib` are symlinks into `/usr`. Check with `ls -ld /bin`. You can ignore the old distinction.

`/opt` is for self-contained add-on software that ships as one folder, such as a vendor's agent installed outside apt. It is a convention, not a rule, so you will only find something there if someone put it there.

## Users and your own files: /home and /root

Each normal user gets a directory under `/home`, such as `/home/deploy`. It holds that user's files and hidden settings, and the user can write to it without sudo. `~` is shorthand for your own home directory.

`/root` is the home directory of the [root user](https://levelrail.com/learn/glossary/#root-user)). It is separate from `/home` and is not the same as `/`. Do not confuse the three: `/` is the top of the tree, `/root` is root's home, `/home/alice` is Alice's home. See [users, groups and sudo](https://levelrail.com/learn/linux/users-groups-and-sudo/)) for how accounts map to these folders.

## Temporary and served data: /tmp and /srv

`/tmp` is scratch space for any user. It can be cleared at reboot or by age, so use it for things you can recreate, never for backups or the only copy of anything.

`/srv` is meant for data a machine serves out, such as files for a web or FTP server. Many people put site content there, for example `/srv/www`. The FHS defines it but packages rarely use it, so you decide how to use it and write it down.

## Virtual directories: /proc, /dev, /sys, /run

Some directories are not on disk at all. The kernel builds them in memory.

- `/proc` exposes processes and kernel state. `cat /proc/meminfo` shows memory, and `/proc/<pid>/` describes one process.
- `/dev` holds device files. Disks appear as `/dev/sda` or `/dev/nvme0n1`, and special files include `/dev/null` (discards writes) and `/dev/urandom` (random bytes).
- `/sys` exposes hardware and driver information.
- `/run` holds runtime data such as PID files and sockets. It is cleared on every boot.

These files take no disk space, so ignore them when you wonder where space went.

## Check it worked

Run these on your server and confirm you can place each result:

```bash
ls -ld /bin /etc /home /root
ls /var/log | head
ls /var/lib | head
head -n 3 /proc/meminfo
df -h /
```

`ls -ld /bin` should show a symlink to `usr/bin` on a current Ubuntu. `/root` should be owned by root with mode `drwx------`, so a normal user gets "Permission denied" if they try to list it.

## Edge cases and gotchas

- **Docker data is under /var/lib/docker.** Images, containers and named volumes all live there, and it can grow large. Read Docker volumes and persistent data before you move or clean it.
- **Separate partitions change the picture.** `/var`, `/home` or `/tmp` can each be their own disk. A full `/var` can break logging and package installs while `/` still shows free space. Run `df -h` to see which one is full.
- **Files in /tmp can vanish.** Do not store uploads, build output you need, or database dumps there.
- **Package files and your files should not mix.** Put hand-installed binaries in `/usr/local/bin` or `/opt`, not `/usr/bin`, so apt upgrades do not clash with them.
- **Hidden files start with a dot.** `ls` hides `.bashrc`, `.ssh` and similar. Use `ls -a` or `ls -la` to see them.
- **/root and / are different places.** Running `rm -rf /root` and `rm -rf /` are very different mistakes, and both are destructive. Read the path twice.
- **Mounted folders hide what was under them.** If you mount a disk on `/srv` while files already exist there, those files are hidden until you unmount it.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `ls: cannot open directory '/root': Permission denied` | You are not root and `/root` is private | Use `sudo ls /root`, or work in your own `/home/<user>` |
| `No such file or directory` for `/etc/nginx/nginx.conf` | The package is not installed, or config is elsewhere | Run `dpkg -l nginx` and `nginx -V` to check install and config path |
| `No space left on device` while `df -h /` shows free space | `/var` or another mount is full | Run `df -h` and clear the full mount, see the full disk lesson |
| `bash: /usr/local/bin/app: No such file or directory` for a file that exists | Wrong architecture or missing interpreter | Run `file /usr/local/bin/app` and install the matching build |
| `cd: /srv/www: No such file or directory` | `/srv/www` is a convention, not created by default | Create it with `sudo mkdir -p /srv/www` |
| Files in `/tmp` disappeared after reboot | `/tmp` is cleared on boot | Move durable files to `/var/lib/<app>` or `/home/<user>` |
| `/var/log` fills the disk | A service logs without rotation | Check sizes with `sudo du -sh /var/log/* \| sort -h` and fix rotation |

## Quick reference

```bash
ls /                      # top-level directories
ls -ld /bin               # is /bin a symlink to /usr/bin?
ls /etc                   # system configuration
ls /var/log               # text logs
ls /var/lib               # service data and state
ls /usr/local/bin         # software you installed by hand
head -n 3 /proc/meminfo   # kernel view of memory
df -h                     # which mount is full
```

## Related lessons

- [Essential Linux commands for servers](https://levelrail.com/learn/server-basics/essential-linux-commands-for-servers/)): the basic commands you use to move around this tree.
- [Linux file permissions explained](https://levelrail.com/learn/server-basics/linux-file-permissions-explained/)): why some of these directories need sudo.
- [Read logs with journalctl](https://levelrail.com/learn/server-basics/read-logs-with-journalctl/)): the other place logs live.
- [Fix a full disk on a Linux server](https://levelrail.com/learn/troubleshooting/fix-a-full-disk-on-a-linux-server/)): what to do when /var fills up.
- [Docker volumes and persistent data](https://levelrail.com/learn/docker/docker-volumes-and-persistent-data/)): where container data ends up on the host.

For a worked example of keeping a site's files in one place, see [self-host a static site with Docker](https://levelrail.com/blog/self-host-static-site-docker/)).

## Next

Now that you know where things live, learn to move through them without breaking anything in [work with files safely](https://levelrail.com/learn/linux/work-with-files-safely/)).

## Frequently asked questions

### What is the root directory in Linux?

The root directory is /, the top of the single filesystem tree. Every file and mounted disk appears somewhere below it. It is not the same as /root, which is the home directory of the [root user](/learn/glossary/#root-user).

### Where are config files stored in Linux?

System-wide config lives in /etc, usually one file or folder per program, such as /etc/ssh/sshd_config or /etc/nginx/. Per-user config lives in hidden files in the user's home directory.

### Where are log files in Linux?

Traditional text logs are under /var/log. On systemd machines the journal holds most service logs, which you read with journalctl.

### What is the difference between /bin and /usr/bin?

Historically /bin held essential commands and /usr/bin held the rest. On current Ubuntu and Debian, /bin is a symlink to /usr/bin, so they are the same place.


## Sources

- [Filesystem Hierarchy Standard (Linux Foundation)](https://refspecs.linuxfoundation.org/fhs.shtml)
- [Ubuntu manpages, hier(7)](https://manpages.ubuntu.com/manpages/noble/en/man7/hier.7.html)
