Chapter 3: Files and directories

The directory tree

Windows gives every disk its own letter. Linux does not: everything, from your documents to the disks themselves, lives in one tree of directories that starts at /. Once you know what the main branches are for, you can guess where almost anything is on any Linux system.

One tree for everything

Every file on a Linux system has a place in one tree. The top of the tree is the root directory, written as a single slash: /. Each directory below it can hold files and more directories, so a file's full name lists the directories you pass through on the way down, separated by slashes. The file issue in the directory etc directly under the root is /etc/issue.

It is drawn upside down, root at the top, branches spreading below. Extra disks, USB sticks and network shares don't get letters: they are attached (mounted) at a directory somewhere in the tree, and their files appear there. Chapter 17 shows how.

[student@servera ~]$ ls /
afs  bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var

What the main directories hold

The directories under / have fixed jobs, agreed between distributions. Select one to see what lives there:

The main directories under /: Select a directory to read what it holds.

DirectoryHoldsSurvives a reboot?
/bootThe kernel and the files that start the systemYes
/devSpecial files that stand for hardware: disks, terminalsRe-created at each boot
/etcSystem-wide configuration, as text filesYes
/homeOrdinary users' home directoriesYes
/rootRoot's own home directory (not under /home)Yes
/runRuntime data for running programs: process IDs, sockets, locksNo, emptied at boot
/tmpScratch space anyone can write to; old files are cleaned up after 10 daysNot to rely on
/usrInstalled software: commands in /usr/bin, admin commands in /usr/sbin, libraries, documentationYes
/varVariable data that grows while the system runs: logs in /var/log, databases, caches, mail, web contentYes

Two more you will meet: /opt for large third-party applications, and /proc and /sys, which aren't on any disk at all. The kernel generates them on the fly to show what is going on inside it.

/bin is really /usr/bin

On RHEL 9, /bin, /sbin, /lib and /lib64 are not real directories but symbolic links, shortcuts to their counterparts inside /usr. The l at the start of the line and the -> arrow show it:

[student@servera ~]$ ls -l /
total 68
dr-xr-xr-x.   2 root root  4096 Nov  3  2024 afs
lrwxrwxrwx.   1 root root     7 Nov  3  2024 bin -> usr/bin
dr-xr-xr-x.   5 root root  4096 Oct  2 08:12 boot
...output omitted...
lrwxrwxrwx.   1 root root     7 Nov  3  2024 lib -> usr/lib
lrwxrwxrwx.   1 root root     9 Nov  3  2024 lib64 -> usr/lib64
...output omitted...
lrwxrwxrwx.   1 root root     8 Nov  3  2024 sbin -> usr/sbin

So /bin/ls and /usr/bin/ls are the same file. Older systems kept them separate; scripts written for them still work because the links exist. You will learn to make links yourself later in this chapter.

Names are case-sensitive

Report.txt, report.txt and REPORT.TXT are three different files on Linux. Most Linux commands and directories use lowercase names, which is why typing them in lowercase is a habit worth building early.

Check your understanding