The Filesystem and FHS: Everything Is a File
In Article 1, ls / showed us a row of directories. This article explains them: the Linux directory tree is organized by a standard (FHS), and each directory has a clear role. We'll also clarify a phrase you often hear: "in Linux, everything is a file."
The directory tree starts from a single root
Unlike Windows (with multiple drives C:, D:...), Linux has only one directory tree, starting from the root directory /. Everything — disks, devices, files — lives somewhere in this tree. Per hier(7), / is "the root directory, where the whole tree begins."
The layout of directories follows the FHS (Filesystem Hierarchy Standard) — a standard for every distro to arrange files consistently. Thanks to it, you know to find config files in /etc and logs in /var/log on any distro.
/
├── bin → usr/bin basic programs (ls, cp...)
├── boot boot files: the Linux kernel, bootloader
├── dev device files (disks, terminals...) — "everything is a file"
├── etc system configuration, specific to this machine
├── home home directories of regular users
├── lib → usr/lib shared libraries
├── proc process & kernel info (virtual filesystem)
├── root home directory of the root user
├── run runtime data (pid, sockets...)
├── sbin → usr/sbin system administration commands
├── sys kernel info & control (virtual)
├── tmp temporary files, can be deleted at any time
├── usr shared software & data, read-only
│ ├── bin main programs (most commands live here)
│ ├── lib libraries
│ └── local software installed locally on this machine
└── var changing data: logs, cache, spool...
A few directories you'll touch the most
Quoting the official descriptions from hier(7), with when you'll care:
- /etc — "host-specific configuration files." This is where you edit service config (nginx, ssh...). When you need to change how a piece of software runs, you usually go to
/etc. - /var — "files that can change in size, such as spool and logs." Most important:
/var/logholds system logs. When debugging a server, you come here. - /usr — "shared, read-only data."
/usr/binholds most commands;/usr/localholds software you install yourself. - /home — "users' home directories." Each regular user has
/home/<name>; root's is/root. - /tmp — "temporary files, can be deleted without warning." Don't keep anything important here.
- /proc and /sys — virtual filesystems: they don't sit on disk; the Linux kernel generates them to expose process/hardware info as files. More on this in the next section.
- /dev — "special files pointing to physical devices." Disks, terminals, devices — all are files here.
What "everything is a file" means
This is one of the foundational ideas of Linux/Unix. Not only text documents are files — Linux represents almost everything as a file so you can read/write it with familiar commands.
Devices are files. Look inside /dev:
ls -l /dev/null /dev/zero /dev/random
crw-rw-rw- 1 root root 1, 3 ... /dev/null
crw-rw-rw- 1 root root 1, 8 ... /dev/random
crw-rw-rw- 1 root root 1, 5 ... /dev/zero
The leading c means "character device" — a device, not a regular file. /dev/null is the "black hole" (anything you write to it disappears — we use it a lot in Article 6), /dev/zero pours out infinite zeros, /dev/random pours out random data. You read/write them like files.
Process and hardware info are files. The virtual filesystem /proc lets you read kernel info like reading a file:
head -3 /proc/cpuinfo # CPU info
ls /proc/self/ # info about the current process
processor : 0
BogoMIPS : 48.00
...
/proc/cpuinfo doesn't exist on disk — the kernel produces it each time you read. Likewise, /proc/<pid>/ holds all the info for the process with that PID (recall Article 2 of the Docker series: we looked at /proc/self/ns/ to see namespaces). This is why "everything is a file" is powerful: knowing just cat, ls, grep, you can inspect both processes and hardware.
File types: read the first character of ls -l
ls -l tells you the type of each entry via the first character:
ls -l /
lrwxrwxrwx ... bin -> usr/bin ← l = symbolic link
drwxr-xr-x ... etc ← d = directory
dr-xr-xr-x ... proc ← d = directory
crw-rw-rw- ... /dev/null ← c = character device
-rw-r--r-- ... /etc/hostname ← - = regular file
-regular fileddirectorylsymbolic link (symlink)c/bdevice (character / block)
Notice bin -> usr/bin: /bin is just a symlink pointing to /usr/bin (modern distros merge them). The remaining rwx... part is permissions — the topic of Article 7.
The
filecommand guesses the content type of a file (file /etc/hostname). Minimal Ubuntu doesn't ship it; add it withapt-get install -y file(Article 11).
Moving around: absolute and relative paths
There are two ways to point to a file/directory:
- Absolute — starting from the root
/:/usr/bin/ls. Always points to exactly one place, no matter where you are. - Relative — counted from the current directory:
bin/ls(if you're in/usr).
A few important symbols:
.the current directory..the parent directory (up one level)~your home directory (/rootor/home/<name>)/the root directory
Try:
cd /usr/share # go there (absolute path)
pwd # /usr/share
cd .. # up one level
pwd # /usr
cd ./bin # go into bin (relative, . is the current directory)
pwd # /usr/bin
cd ~ # back to home directory
cd with no argument also takes you back to ~. cd - returns to the directory you just left.
🧹 Cleanup
This article only reads/navigates and doesn't create files, so there's nothing to clean up. Keep the linuxlab lab for the next article.
Wrap-up
Linux has a single directory tree from /, arranged by the FHS standard: /etc for configuration, /var/log for logs, /usr/bin for commands, /home for users, and /proc and /dev as virtual filesystems exposing info/devices. The "everything is a file" philosophy lets you read the CPU, processes, and devices with familiar file commands. And you move around the tree with absolute/relative paths using ., .., ~.
You now know where files live and can view them. Article 3 teaches how to create, copy, move, delete, and find files — the operations you do every day.