The Linux Filesystem Explained: /etc, /var and More
A guide says "check the logs in /var/log" or "edit the file in /etc", and the names look like code. They are ordinary folders, and every Linux machine puts them in the same places. This lesson maps the Linux filesystem: its single tree, what the main folders hold, how to write a path, and where to look first.
One tree, starting at the root
A filesystem is the way an operating system organises files and folders on storage; the word also means the whole tree you see. Linux has one tree, starting at the root directory, written as a single forward slash, /. Every file sits somewhere below it.
Windows gives each disk a drive letter, such as C: and D:, and uses backslashes, as in C:\Users\asha. Linux has no drive letters. A second disk or a memory stick is mounted: attached to an empty folder, called its mount point, and its files appear inside that folder.
A server's data disk might appear at /mnt/data, and on Ubuntu a memory stick appears under /media/ and your user name. macOS also has one tree, and shows extra disks under /Volumes.
Unix tradition sums this up as "everything is a file": devices and live system information also appear as names in the tree, so ls and cat (lesson 4) work on them too.
The root directory is not root, the administrator account (lesson 7), whose home folder is /root.
The key directories and what they hold
Most distributions follow the same layout, the Filesystem Hierarchy Standard (FHS). The tree shows the eight top-level folders you will meet most. Notice the two pink ones: they are not ordinary documents.
/etc holds configuration: settings for the machine and its services, mostly in plain-text files. /etc/hosts, for example, pairs computer names with IP (Internet Protocol) addresses.
/var holds variable data, which changes as the system runs: logs in /var/log (time-stamped records of what programs did and what went wrong), queued mail and databases' data.
/home holds one folder per person, such as /home/asha, for their documents and personal settings. A Mac uses /Users instead.
/usr holds installed programs and their shared files. Most commands, including those from the package manager (lesson 11), live in /usr/bin (bin is short for binaries, ready-to-run programs). It is not for users' files.
/bin holds essential commands such as ls and cp. On most current distributions, including Ubuntu, Debian and Fedora, it is a symbolic link (a shortcut) to /usr/bin, so both names open the same folder.
/tmp is scratch space for temporary files. Many systems empty it when they restart, so keep nothing important there.
/dev (devices) holds a special file for each device: a disk might be /dev/sda, and /dev/null throws away anything written to it.
/proc is not stored on disk. The kernel writes its contents the moment you read them, such as processor details in /proc/cpuinfo and a numbered folder per running process, named after its PID, the process ID (lesson 3). Think of a live status board, not a room. macOS has no /proc.
Paths: the route to a file
A path is the route to a file or folder: names separated by forward slashes. The two kinds differ in where the route starts.
An absolute path starts with / and spells out the whole route from the root, such as /etc/hosts. It means the same file wherever you are.
A relative path has no leading slash and starts from your working directory, the folder the shell is in (lesson 4). In it, . is the current folder and .. is the one above, its parent, so ../notes means "go up one level, then into notes".
The tilde, ~, stands for your home folder: the shell turns ~/notes into, for example, /home/asha/notes. The diagram reaches one file from two folders.
Notice that the absolute path is the same from A and B, while the relative path changes. Also, Linux treats capitals as different letters, so Notes and notes are two folders; macOS ignores case by default.
Where to look first
Because the layout is standard, most searches start in one of four places. Follow the flowchart from what you need to the folder.
Configuration often sits in a subfolder named after the program, such as /etc/ssh for SSH (Secure Shell), the secure remote login (lesson 15). Besides /var/log, many distributions keep a log store called the journal, read with a command (lesson 13).
To see where a program is stored, type which and its name: which ls prints a path such as /usr/bin/ls on Ubuntu or /bin/ls on a Mac.
Hidden files start with a dot
A file or folder whose name starts with a dot, such as .bashrc, is hidden: ls and Finder leave it out. ls -a (all) shows everything, including the . and .. entries.
Programs keep your personal settings in hidden files. ~/.bashrc holds settings for bash, such as shortcuts and the prompt's look, and bash reads it when it starts in a new terminal window. On a Mac, zsh reads ~/.zshrc instead, if you have created one.
Hidden is tidiness, not protection: permissions do the protecting (lesson 6). Remember the split: /etc holds settings for the whole system, and dot files in your home hold yours.
Check yourself
In /home/asha/projects, cat ../notes/plan.txt works. In /tmp, the same command says "No such file or directory". Why?
A relative path starts from the working directory. From /tmp, .. is the root, so the path means /notes/plan.txt, which does not exist. The absolute path /home/asha/notes/plan.txt works from anywhere.
A service on a Linux server will not start. Which two folders do you check first, and why?
/var/log, because the service may have logged the error, and /etc, because a wrong setting in its configuration is a common cause.
A colleague wants to delete /proc/meminfo to free disk space. Why would that not help?
/proc is not stored on disk. The kernel writes each file's contents only when you read it, so /proc/meminfo takes up no disk space.