Skip to content

A guide you are following says: “The settings for this program are in /etc. If it fails to start, check the logs in /var/log.” You can reach any directory with one cd, and lesson B05.1 showed you the top of the tree:

Output (course VM)
bin home mnt sbin.usr-is-merged usr
bin.usr-is-merged lib opt snap var
boot lib64 proc srv
cdrom lib.usr-is-merged root swap.img
dev lost+found run sys
etc media sbin tmp

Twenty-six names, and none of them says what it holds. The guide expects you to know where settings and logs live, and you do not know yet.

By the end of this lesson, you can say where to look for a setting, a log, a program, a user’s file, a temporary file, a device, or information about a process or the hardware. You can also tell which directories are on the disk and which the kernel creates in memory.

This lesson does not use ~/lab. All output comes from the course VM, because other Linux systems show different contents here. Every command only reads.

Lesson B05.1 explained /home and /root, the root account’s home directory. With /home, eight directories answer the questions in the opening:

Directory In short What it holds
/etc Settings Configuration files for this computer: settings that apply to the whole system
/home Users’ files One home directory for each regular user, such as /home/learner
/tmp Temporary files Files that programs and users create for a short time
/var Logs, changing files Files that grow and change while the system runs, such as the logs in /var/log
/usr Programs The installed programs and the files that come with them
/dev Device files Files that stand for devices, such as disks and terminals
/proc Processes, kernel Information about the running processes and the kernel
/sys Hardware, kernel Information about the kernel and the devices it manages

The purposes follow the manual page hier(7) and the Filesystem Hierarchy Standard (Further reading).

List the first 20 names in /etc:

Terminal window
ls /etc | head -n 20
Output (course VM)
adduser.conf
alsa
alternatives
anacrontab
apg.conf
apm
apparmor
apparmor.d
apport
apt
avahi
bash.bashrc
bash_completion
bindresvport.blacklist
binfmt.d
bluetooth
brlapi.key
brltty
brltty.conf
ca-certificates

The | passes the output of ls to head, as in lesson B04.3. Several names end in .conf, short for configuration. You met bash.bashrc, which Bash reads for every terminal window, in lesson B03.3, and /etc/skel in lesson B05.3.

How many names are there in total? wc -l counts the lines it receives:

Terminal window
ls /etc | wc -l
Output (course VM)
233

Many programs keep their system-wide settings here. Your own settings stay in hidden files in your home directory, such as ~/.bashrc.

Terminal window
ls /usr
Output (course VM)
bin games include lib lib64 libexec local sbin share src

Lesson B04.4 found head in /usr/bin, and /usr/bin is the main directory for the programs that users run. Look at the file and count the names in the directory:

Terminal window
ls -l /usr/bin/head
ls /usr/bin | wc -l
Output (course VM)
-rwxr-xr-x 1 root root 43528 Aug 25 17:09 /usr/bin/head
1478

head is an ordinary file, owned by root, and /usr/bin holds 1478 names. The other directories hold what those programs need: lib holds libraries, code that many programs share, and share holds data such as the documentation in /usr/share/doc (lesson B04.3). The files in /usr change when software is installed or updated (module B12). Note the spelling: usr, not user.

Terminal window
ls /var
Output (course VM)
backups crash local log metrics run spool
cache lib lock mail opt snap tmp

/var holds files that change while the system runs. log is the directory from the opening: programs write their logs there, files where they record what they did and what went wrong. Other directories, such as cache and spool, hold data that programs keep for later.

Terminal window
ls -a /tmp
Output (course VM)
.
..
.font-unix
.ICE-unix
.iprt-localipc-DRMIpcServer
snap-private-tmp
systemd-private-0d53e9a41d34414db8e5562b12d1a1d6-colord.service-jjZ0oy
systemd-private-0d53e9a41d34414db8e5562b12d1a1d6-ModemManager.service-Y7hNhC
systemd-private-0d53e9a41d34414db8e5562b12d1a1d6-polkit.service-B7CtF6
…
.X0-lock
.X1024-lock
.X1025-lock
.X11-unix
.X1-lock
.XIM-unix

/tmp holds temporary files that programs and users create. Programs that run in the background, such as polkit, have private directories here. The names that start with systemd-private- contain random letters and digits, so yours look different, and the list changes with the programs that run.

Unlike most directories outside your home directory, /tmp lets every account create files in it. Its permissions, drwxrwxrwt, say so; module B11 teaches you to read them.

Do not keep anything in /tmp that you want to keep. Ubuntu empties it each time the system starts, and also removes files that nobody has used or changed for 30 days. The rule is one line in the file /usr/lib/tmpfiles.d/tmp.conf, which the manual page tmpfiles.d(5) explains.

Terminal window
ls /dev | head -n 20
Output (course VM)
autofs
block
bsg
btrfs-control
bus
cdrom
char
console
core
cpu
cpu_dma_latency
cpu_wakeup_latency
cuse
disk
dma_heap
dri
ecryptfs
fb0
fd
full

Each name in /dev stands for a device. In lesson B03.2, tty printed /dev/pts/0 for your terminal window and /dev/tty3 for a text console. cdrom is the VM’s virtual CD drive. A program that uses one of these files talks to the device through the kernel.

Here is the start of /proc. Guess first: what kind of names will you see?

Terminal window
ls /proc | head -n 30
Run it, then compare with your guess
Output (course VM)
1
10
11
12
1297
13
1307
1311
1320
1335
…
1846

Numbers. They are PIDs, the numbers the kernel gives to running processes, which ps showed in lesson B03.2. Each running process has a directory in /proc, named after its PID. Your numbers will differ.

Other files in /proc describe the whole system, such as its memory:

Terminal window
head -n 3 /proc/meminfo
Output (course VM)
MemTotal: 4005444 kB
MemFree: 1702716 kB
MemAvailable: 2865052 kB

MemTotal is a little less than the 4096 MB you gave the VM in lesson B02.3. No program wrote this file: the kernel produces its text when a program reads it, so your numbers will differ.

Terminal window
ls /sys
Output (course VM)
block class devices fs kernel power
bus dev firmware hypervisor module

/sys is also produced by the kernel. It describes the devices the kernel knows about, sorted in different ways: block for disks, bus for the connections between devices, class for kinds of devices.

In lesson B02.3, the installer formatted a partition as ext4 and used it for /. Are all eight directories on that partition?

Start with ls -ld (lesson B05.3). Guess first: what size does it report for /proc, a directory full of entries?

Terminal window
ls -ld /proc /sys /dev /tmp /run
Run it, then compare with your guess
Output (course VM)
drwxr-xr-x 19 root root 4180 Nov 5 06:56 /dev
dr-xr-xr-x 234 root root 0 Nov 5 06:56 /proc
drwxr-xr-x 34 root root 880 Nov 5 06:56 /run
dr-xr-xr-x 13 root root 0 Nov 5 06:57 /sys
drwxrwxrwt 18 root root 4096 Nov 5 06:57 /tmp

The size, in the fifth column, is 0 for /proc and /sys. Their contents are not stored anywhere: the kernel produces them when a program asks.

A size of 0 is a clue, but /dev and /run show other sizes. The command findmnt gives the full answer: for a path, it prints the file system that holds it. The line below runs findmnt once for each of ten directories; you do not need to type it.

Terminal window
for d in / /home /etc /usr /var /tmp /dev /proc /sys /run; do findmnt -n -o TARGET,FSTYPE --target "$d"; done
Output (course VM)
/ ext4
/ ext4
/ ext4
/ ext4
/ ext4
/ ext4
/dev devtmpfs
/proc proc
/sys sysfs
/run tmpfs

Each line belongs to one directory, in the order of the command. The first column is a mount point: the directory where a file system is attached to the tree. The second is the type of that file system.

  • The first six lines say / ext4: /, /home, /etc, /usr, /var, and /tmp are all on the ext4 file system on the VM’s disk. Their files stay when you turn the VM off, except in /tmp, which Ubuntu empties when the system starts again.
  • /dev, /proc, /sys, and /run are file systems of their own. Their types, devtmpfs, proc, sysfs, and tmpfs, are file systems that the kernel provides in memory, not on the disk, each time the system starts.

So on the course VM, /tmp is on the disk. Other Linux systems may keep it in memory; findmnt tells you which.

One more detail in ls / needs an explanation. Look at the long listing:

Terminal window
ls -l /
Output (course VM, shortened)
total 4008028
lrwxrwxrwx 1 root root 7 Apr 22 2024 bin -> usr/bin
drwxr-xr-x 2 root root 4096 Feb 26 2024 bin.usr-is-merged
…
lrwxrwxrwx 1 root root 7 Apr 22 2024 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Apr 22 2024 lib64 -> usr/lib64
…
lrwxrwxrwx 1 root root 8 Apr 22 2024 sbin -> usr/sbin
…

These four lines start with l, not d, and end in an arrow. bin is not a directory but a symbolic link, or link: a name that points to another path. Lesson B06.4 in module B06 explains links. readlink prints the path that a link points to:

Terminal window
readlink /bin /sbin /lib /lib64
Output (course VM)
usr/bin
usr/sbin
usr/lib
usr/lib64

The paths are relative, read from /, where the links are. So on this system, /bin and /usr/bin are one directory with two names, and /bin/head is the same file as /usr/bin/head. This is why type head said /usr/bin/head in lesson B04.4: the programs are stored in /usr, and the names in / only point there. This layout is called merged /usr.

The three directories ending in .usr-is-merged are left from the change to this layout; this lesson does not cover them.

Eight system directories in /, on the disk and in memory Below /, the directories /etc (settings), /home (users' files), /tmp (temporary files), /var (logs, changing files) and /usr (programs) are stored on the disk, in the ext4 file system. /bin is a link to usr/bin, and the same is true for /sbin, /lib and /lib64. The directories /dev (device files), /proc (processes, kernel) and /sys (hardware, kernel) are made by the kernel in memory. / Stored on the disk (ext4) /etc Settings /home Users' files /tmp Temporary files /var Logs, changing files /usr Programs /bin -> usr/bin link Same for /sbin, /lib, /lib64 Made by the kernel in memory /dev Device files /proc Processes, kernel /sys Hardware, kernel
Eight system directories in /, on the disk and in memory Below /, the directories /etc (settings), /home (users' files), /tmp (temporary files), /var (logs, changing files) and /usr (programs) are stored on the disk, in the ext4 file system. /bin is a link to usr/bin, and the same is true for /sbin, /lib and /lib64. The directories /dev (device files), /proc (processes, kernel) and /sys (hardware, kernel) are made by the kernel in memory. / Stored on the disk (ext4) /etc Settings /home Users' files /tmp Temporary files /var Logs, changing files /usr Programs /bin -> usr/bin link Same for /sbin, /lib, /lib64 Made by the kernel in memory /dev Device files /proc Processes, kernel /sys Hardware, kernel
Simplified model. The eight directories of this lesson below /: five stored on the disk in the ext4 file system, three made by the kernel in memory, and /bin as a link to usr/bin.

In words: below /, the region with a solid border holds the directories stored on the disk, in the ext4 file system: /etc, /home, /tmp, /var, and /usr, with /bin as a link to usr/bin (the same for /sbin, /lib, and /lib64). The region with a dashed border holds the directories that the kernel makes in memory: /dev, /proc, and /sys. Each box carries the short purpose from the first table.

The diagram leaves out the other entries of /, most importantly /run, which is also made in memory. The table names them.

Name in / What it holds
/root The root account’s home directory (lesson B05.1)
/boot The files needed to start the system
/run Information about the system since it was started, kept in memory
/media Mount points for removable media, such as a USB stick
/mnt A mount point for a file system that is attached for a short time
/opt Add-on software packages
/srv Data that this system serves to others, for example as a web server
/lost+found Pieces of files recovered after a disk error or a crash

/snap, /cdrom, and swap.img are not described in hier(7); they come from Ubuntu’s software and installer, and later modules cover them.

Two facts from this lesson combine into a known attack: every account can create files in /tmp, and a link can point to any path. Suppose a program that runs as root always writes to the same name in /tmp. Another account creates a link with that name first, pointing to a file in /etc. The program follows the link and overwrites that settings file.

MITRE’s list of software weaknesses describes this as CWE-59: Improper Link Resolution Before File Access: a program opens a file by its name without checking that the name leads to the file it intends.

The Linux kernel has a defense against this case, the setting fs.protected_symlinks. When it is 1, the kernel follows a link in a directory such as /tmp, which every account can write to, only if the link belongs to the account that follows it or to the owner of the directory. Ubuntu 24.04 turns it on by default, and you can read its value in /proc, in the file /proc/sys/fs/protected_symlinks. The weakness is still in the program, and the setting covers only links: a program that creates its temporary files safely, for example under names nobody can guess, does not depend on it.

Goal: Decide where five files are, whether each is on the disk, and check that they exist.

  1. Without running anything, say which directory to look in for each:
    • the program wc
    • the Bash settings that apply to every user
    • your own home directory
    • the device file for the VM’s CD drive
    • the information about the process with PID 1
  2. For each answer, say whether it is stored on the disk or made by the kernel in memory.
  3. Check that all five paths exist, with one ls -d command.

Expected: ls -d prints the five paths and no No such file or directory message.

Hint

type from lesson B04.4 shows where a program is. Device names are in /dev.

Solution
File Path Stored
The program wc /usr/bin/wc On the disk
Bash settings for every user /etc/bash.bashrc On the disk
Your home directory /home/learner On the disk
The CD drive’s device file /dev/cdrom In memory
Information about PID 1 /proc/1 In memory
Terminal window
ls -d /usr/bin/wc /etc/bash.bashrc /home/learner /dev/cdrom /proc/1

ls -d prints the five paths and no error; -d stops ls from listing what is inside /home/learner and /proc/1.

  • /etc holds settings, /var logs and other changing files, /usr the programs, /home the users’ files, and /tmp temporary files that any account can create and that Ubuntu removes when the system starts.
  • /dev holds device files, /proc information about processes and the kernel, and /sys about the hardware.
  • On the course VM, findmnt shows /dev, /proc, /sys, and /run as file systems that the kernel provides in memory; the others are on the disk.
  • /bin, /sbin, /lib, and /lib64 are links into /usr, so /bin/head and /usr/bin/head are the same file.

Next, Practice: Navigating the Filesystem puts lessons B05.1 to B05.4 to work in one task.