What you'll learn
- Find config, logs and binaries
- Describe what lives in /etc, /var, /usr, /home and the other top-level directories
- Locate programs, config files and logs with which, find and ls
- Find what is filling a disk with df and du
Learn what lives in /etc, /var, /usr, /home and the other top-level folders, and find any config, log or program.
Why it matters
When a service misbehaves on a server, the questions are always the same: where is its configuration, where are its logs, and which program is actually running? On Linux the answers follow a shared map called the Filesystem Hierarchy StandardThe shared map of where things live on Linux, such as config in /etc and logs in /var/log; FHS. (FHS). Once you know the map, you can find your way around almost any Linux machine, including one you have never seen before.
One tree, starting at /
Windows has drive letters (C:\, D:\). Linux has a single tree that starts at the root directoryThe top of the single Linux directory tree, written /., written /. Extra disks, USB drives and network shares are mountedAttached into the directory tree at a folder, which is how extra disks and drives appear on Linux instead of drive letters. somewhere inside that tree instead of getting their own letter. Run ls / and you will see the top level.
| Directory | What it holds | Example |
|---|---|---|
/etc | System-wide configuration, mostly plain text | /etc/ssh/sshd_config, /etc/hosts |
/var | Data that changes while the system runs | /var/log/ (logs), /var/lib/ (databases, package state) |
/usr | Installed programs and their read-only files | /usr/bin/python3, /usr/share/doc/ |
/bin, /sbin | Essential commands (on modern distros, links into /usr) | /bin/ls |
/home | One folder per normal user | /home/alex |
/root | The root user's home folder | |
/tmp | Temporary files, often cleared on reboot | |
/opt | Optional, self-contained third-party software | /opt/someapp/ |
/dev | Device files for disks, terminals and more | /dev/sda, /dev/null |
/proc, /sys | Virtual files the kernel generates about processes and hardware | /proc/cpuinfo |
/boot | Kernel and bootloader files | |
/mnt, /media | Mount points for extra or removable drives |
A useful rule of thumb: config in /etc, changing data and logs in /var, programs in /usr, people in /home.
"Everything is a file"
Linux exposes a lot of the system as files. Your disk is /dev/sda (or /dev/vda in many VMs). /dev/null is a black hole that discards whatever is written to it. /proc/meminfo is not stored on disk at all: the kernel generates its contents when you read it.
cat /proc/cpuinfo | grep "model name" | head -1
cat /proc/meminfo | head -3This is why so many admin tasks come down to reading or editing a text file.
Finding things
Where is a program?
which python3 # path of the command your shell would run
type ls # also shows aliases and shell built-inswhich python3 prints something like /usr/bin/python3.
Where is a config file?
Configuration for a program is usually in /etc/<program> or /etc/<program>.conf:
ls /etc/ssh/
ls /etc | head -30When you do not know the name, search by name with find. Searching system folders produces "Permission denied" noise for folders you cannot read, so send errors to /dev/null:
find /etc -name "*.conf" 2>/dev/null | head
find / -name "sshd_config" 2>/dev/nullWhere are the logs?
Traditional text logs live in /var/log:
ls -lh /var/logOn Ubuntu you will see syslog, auth.log (logins and sudo), dpkg.log (package installs) and folders for individual services. Many systems also keep logs in the systemd journal, which a later lesson covers.
What is using my disk?
df -h # free space per mounted filesystem
du -sh /var/log # total size of one folder
sudo du -sh /var/* 2>/dev/null | sort -h | tail -5df answers "how full is each disk?" and du answers "which folder is big?". A full disk is one of the most common causes of a broken server, and /var/log is a frequent culprit.
Absolute and relative paths, again
An absolute pathA path that starts at / and works from any current folder, such as /etc/hosts. starts at / and works from anywhere: /etc/hosts. A relative pathA path interpreted from the current folder, such as ../notes.txt. starts from your current folder: ../notes.txt. In scripts and config files, prefer absolute paths, because the "current folder" of a script run by a scheduler is often not what you expect.
Common mistakes
- Editing files in
/usr. Package updates overwrite them. Put local configuration in/etcand your own scripts in/usr/local/binor your home folder. - Deleting files in
/var/logto free space while a service has them open. The space is not freed until the service restarts. Use the log rotation and journal tools you will meet later instead. - Treating
/tmpas storage. It can be wiped at reboot. - Running
find /without silencing errors, then missing the real result in a wall of "Permission denied".
Recap
- Linux has one tree rooted at
/; extra drives are mounted into it. - Config lives in
/etc, logs and changing data in/var, programs in/usr, users in/home. /proc,/sysand/devexpose the kernel and devices as files.which,find,ls /var/log,df -handdu -shfind programs, configs, logs and disk hogs.
Try it
The Do tab has a scavenger hunt through your practice system's filesystem.
Key terms (5)
- Filesystem Hierarchy Standard
- The shared map of where things live on Linux, such as config in /etc and logs in /var/log; FHS.
- root directory
- The top of the single Linux directory tree, written /.
- mounted
- Attached into the directory tree at a folder, which is how extra disks and drives appear on Linux instead of drive letters.
- absolute path
- A path that starts at / and works from any current folder, such as /etc/hosts.
- relative path
- A path interpreted from the current folder, such as ../notes.txt.