Linux Command Line · Lesson 5 of 43
The Linux filesystem layout
Tour the Linux directory tree from the root: what /home, /etc, /usr, /var, /tmp and /bin hold, and why there are no drive letters.
UNDERSTAND IT. THEN TRY IT.
What you can do after this lesson
You will know where things live on a Linux machine, which makes every other command easier: you will know where to look for settings, logs, programs and your own files, and which places to leave alone.
One tree, starting at the root
Windows has drive letters such as C: and D:. Linux has a single tree of directories that begins at the root directory, written as a single slash: /. Everything else, including other disks and USB sticks, is mounted at some folder inside that tree. A path always reads from left to right, with / separating the names.
Do not confuse the root directory / with the root user (the administrator), or with /root, which is the administrator's home folder. The words sound alike but mean three different things.
The main directories
The layout follows a standard called the Filesystem Hierarchy Standard, so it is nearly the same on every distribution:
| Directory | What it holds |
|---|---|
/home |
Personal folders of users, such as /home/asha |
/root |
Home folder of the root user |
/etc |
System-wide configuration files, mostly plain text |
/var |
Data that changes as the system runs: logs, caches, mail, databases |
/tmp |
Temporary files, often cleared on reboot |
/usr |
Installed programs, libraries and shared data |
/bin, /sbin |
Essential commands (often links into /usr) |
/opt |
Optional, self-contained third-party software |
/dev |
Device files that represent hardware |
/proc, /sys |
Virtual files that expose the kernel and running processes |
/boot |
Files needed to start the system |
/mnt, /media |
Places to mount other disks |
You can confirm that the standard directories exist on your machine:
ls -d /bin /etc /home /tmp /usr /var/bin
/etc
/home
/tmp
/usr
/varThe -d option lists the directories themselves instead of their contents.
/etc: configuration as text
Settings for the system and for services live in /etc, as ordinary text files you can read. One famous file lists the accounts on the machine. This command shows the line for the administrator account:
grep "^root:" /etc/passwdroot:x:0:0:root:/root:/bin/bashEach line has fields separated by colons: user name, a placeholder for the password (the real hash lives elsewhere), the numeric user ID, group ID, a description, the home directory and the login shell. You can read files in /etc as a normal user, but changing most of them needs administrator rights.
/var and /tmp: data that changes
Services write logs to /var/log, and web servers, mail systems and databases keep their data under /var. If a disk fills up unexpectedly, this is where to look. /tmp is for scratch files that any program may create; do not store anything important there, because it can be emptied at any time.
/usr and /bin: programs
/usr/bin contains most commands you run, including ls. Older systems kept essential commands in /bin and /sbin separately. Many modern distributions, including Debian, Ubuntu, Fedora and the Red Hat family, have merged them, so /bin is a symbolic link to /usr/bin, a kind of shortcut you will meet in the lesson on links. When you type a command name, the shell searches a list of directories, called the PATH, for a program with that name.
/dev, /proc and "everything is a file"
Hardware appears as files under /dev. For example, /dev/null is a special file that discards anything written to it, and you will use it often to hide unwanted output. /proc shows live information about the system and its processes as if it were files. Because of this design, the same tools that read text files can read system information.
Hidden files and case
Files whose names begin with a dot, such as .bashrc or .ssh, are hidden: ls skips them unless you add -a. Programs use them for personal settings in your home folder. Remember too that names are case sensitive, so Report.txt and report.txt can both exist in the same folder.
Common mistakes
Looking for drive letters. There are none. Other disks appear as folders after they are mounted.
Editing system files without understanding them. Files in /etc control the whole machine. Make a copy before you change one.
Saving important work in /tmp. It is designed to be temporary.
Mixing up / and ~. / is the top of the whole tree; ~ is your own home directory, a small part of it.
Exercise
Run ls / on your own machine and match each name you see against the table. Then run ls /etc | head -n 10 and ls /var/log, and open one text file in /etc with head -n 5 /etc/hostname if it exists. Write down three directories you should not change without a good reason and say why.
KNOWLEDGE CHECK
A quick check. You’ve got this.
Try each question. Every answer comes with an explanation.
Ready for the next small win?
Mark the lesson complete when you are ready.