The filesystem hierarchy
Why everything starts at /, what lives in /etc, /var, /usr, /home and /proc, and "everything is a file".
Windows has drive letters (C:\, D:\). Linux has one tree that starts at the root directory, /. Every file, disk, USB stick and network share appears somewhere under it. The layout follows the Filesystem Hierarchy Standard (FHS), so once you learn it, you'll find your way around any distribution.
The top level#
(Your list may include a few extras, such as lost+found or snap.)
Where do programs live?#
When you type python3, the shell searches the directories listed in the PATH variable, in order:
/usr/binholds programs installed by the package manager./usr/sbinholds admin programs (useradd,sshd)./usr/local/bincomes first, so a tool you install there overrides the distro's version.
You'll learn to change PATH in Environment variables & shell configuration.
/etc: configuration as text#
Almost all system configuration is plain text in /etc, which is a big part of what makes Linux scriptable:
Edit these files with care (and usually with sudo). Make a backup copy first: sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.
/var: things that grow#
/var is where running systems write data:
When a disk fills up unexpectedly, /var (logs, Docker images, databases) is usually the first place to look. See Disks & storage.
"Everything is a file"#
Linux exposes many things through the file interface:
/proc and /sys aren't on disk at all. The kernel generates their contents on demand:
Tools like ps, top and free simply read these files and format them nicely.
Your home directory#
/home/<you> (written ~) is yours: documents, code, downloads and your personal configuration in hidden "dotfiles":
- Names starting with
.are hidden from plainls. Usels -ato see them. ~/.bashrcconfigures your shell,~/.ssh/holds your SSH keys, and~/.config/holds most apps' settings..means "this directory" and..means "the parent directory".
Mount points: disks join the tree#
Extra disks, partitions and USB sticks don't get letters. They're mounted onto a directory, and their contents appear there:
A server might mount a big data disk at /var/lib/mysql or /data. You'll learn how in Disks & storage.
Case, extensions and names#
- Names are case-sensitive:
Report.txtandreport.txtcan sit side by side. - Extensions (
.txt,.sh) are just part of the name. Linux decides how to treat a file by its permissions and content, not its extension (file nameshows what a file really is). - Avoid spaces and special characters in names you'll use on the command line. Use
my-notes.txtormy_notes.txt. /can't appear in a file name, and neither can the NUL byte. Almost anything else can.
Common mistakes#
- Looking for drive letters. There's a single tree starting at
/, and other disks are mounted into it (e.g./mnt/usb). - Mixing up
/and~./is the root of the whole system, while~is your home directory,/home/<you>. - Storing your own files in system directories like
/usror/etc. Keep them in your home directory, and put server data under/srvor/var/lib. - Forgetting that names are case-sensitive.
Report.txtandreport.txtare different files.
What's next#
With the map in mind, let's move around it: pwd, ls, cd and paths.
Check your understanding
Quick quiz
1.Where do system-wide configuration files live?
2.Your server's disk is filling up with log files. Which directory is the most likely culprit?
3.What is special about
/procand/sys?
Finished reading?
Mark this lesson complete to track your progress.