Skip to main content

Navigating the Linux Filesystem and FHS

Learn the Linux Filesystem Hierarchy Standard, absolute vs relative paths, and the ls, find, du, and ln commands every production server needs.

30 Terms

Overview and What You Will Learn

The Linux filesystem is a single tree that starts at /, laid out according to the Filesystem Hierarchy Standard (FHS). Configuration lives in /etc, logs and changing data in /var, programs in /usr, and live kernel data in /proc. Learn this map once and every Linux server feels familiar.

By the end of this lab you will:

  • Explain what lives in each top-level directory
  • Choose between absolute and relative paths and know when each breaks
  • Navigate with cd, ls, and pwd using the flags that matter
  • Create, copy, move, and delete files safely
  • Find files with find, locate, and which
  • Read logs with less, head, and tail
  • Check disk usage with df and du, and manage symlinks

Why This Matters in Production

Containers, Kubernetes volumes, Ansible tasks, and CI/CD jobs all read and write specific paths. Misunderstood paths cause a surprising share of incidents: a script that works locally but fails in CI because a relative path resolves elsewhere, a cron job that cannot find a binary because cron has a minimal PATH, or a Dockerfile COPY that silently copies nothing.

When an on-call engineer at a streaming company such as Hotstar or Spotify is paged at 2 AM, the FHS is what makes the first minute efficient: logs are under /var/log, service config is under /etc, and the disk check is df -h.

Core Principles

The FHS gives every kind of file a predictable home, which is why the same commands work on Ubuntu, Debian, RHEL, and Amazon Linux.

flowchart TD R(["/ root"]) --> E["/etc
configuration"] R --> V["/var
logs and data"] R --> U["/usr
programs, libraries"] R --> H["/home
user files"] R --> P["/proc and /sys
virtual kernel data"] R --> D["/dev
device files"] classDef root fill:#475569,color:#ffffff classDef cfg fill:#326CE5,color:#ffffff classDef data fill:#10B981,color:#ffffff classDef virt fill:#8B5CF6,color:#ffffff class R root class E,U cfg class V,H data class P,D virt
Directory What it holds Notes
/etc System and service configuration Text files, safe to back up
/var/log Application and system logs First stop during incidents
/var/lib Persistent service data Databases, package state
/run PID files and sockets In memory, cleared on reboot
/tmp Temporary files Often cleared on reboot
/home, /root User home directories /root is the root user's home
/usr/bin, /usr/sbin Programs /bin and /sbin link here on modern distros
/usr/local Locally installed software Not managed by the package manager
/opt Third-party application bundles One directory per vendor or app
/proc, /sys Virtual kernel interfaces Generated in memory, nothing on disk
/dev Device files Disks, terminals, /dev/null
/boot Kernel and bootloader Keep free space here

An absolute path starts at / and always points to one file. A relative path starts from the current working directory, so the same text can mean different files depending on where the process runs.

Bash
/etc/nginx/nginx.conf
/home/rahul/.ssh/id_ed25519
# Relative: depends on the current directory
./deploy.sh
../config/app.yaml
logs/error.log
Common Mistake

Relative paths in cron jobs, systemd units, and CI steps usually fail because the working directory is not what you expect. Cron starts jobs in the user's home directory with a minimal PATH. Use absolute paths in all automation.

/proc is not stored on disk. The kernel generates it on demand, and each running process has a directory /proc/PID/ with live details.

Bash
cat /proc/1/cmdline | tr '\0' ' ' # command that started PID 1
ls -l /proc/$$/fd # open file descriptors of this shell
cat /proc/meminfo # live memory statistics
cat /proc/sys/net/ipv4/ip_forward # current kernel parameter value

Detailed Step-by-Step Practical Lab

Milestone 1: How to Navigate with cd, pwd, and ls
Bash
pwd
# /home/rahul
cd /etc
ls -la | head -30
# List another directory without leaving
ls -la /var/log/
cd ~ # home directory (same as plain cd)
cd /etc
cd - # jump back to the previous directory
# /home/rahul
Milestone 2: How to List Files with Useful ls Flags
Bash
ls -lh /var/log/ # long format, human-readable sizes
ls -la ~ # include hidden dotfiles
ls -lt /var/log/ # newest modification first
ls -ltr /var/log/ # newest last, easy to read at the bottom
ls -R /etc/ssh/ # recursive listing
ls -d /etc/*/ # directories only
Milestone 3: How to Create, Copy, Move, and Delete Files
Bash
mkdir -p /tmp/lab/configs/nginx # -p creates parent directories
touch /tmp/lab/app.log
touch /tmp/lab/{file1,file2,file3}.txt # brace expansion makes three files
cp /etc/hosts /tmp/lab/hosts.backup
cp -r /etc/ssh /tmp/lab/ssh-backup # -r for directories
mv /tmp/lab/file1.txt /tmp/lab/renamed.txt # move or rename
rm /tmp/lab/file2.txt
rm -r /tmp/lab/ssh-backup

Guard variables before using them in a delete. The :? form aborts the script if the variable is empty or unset:

Bash
DIRNAME="/tmp/lab"
rm -rf "${DIRNAME:?DIRNAME is not set}/"
Security

rm -rf $DIRNAME/ with an empty variable becomes rm -rf /. Always quote variables, use ${VAR:?}, and run ls on the target first.

Milestone 4: How to Find Files with find and locate
Bash
# By name
find /etc -name "nginx.conf"
find /var/log -iname "*.log" # case insensitive
# By time and size
find /var/log -type f -mtime -1 # changed in the last 24 hours
find / -xdev -type f -size +100M 2>/dev/null
# By permission
find /home -name ".ssh" -type d -perm 700
# Preview first, then delete
find /tmp -name "*.tmp" -mtime +7 -print
find /tmp -name "*.tmp" -mtime +7 -delete
# Index-based search (refresh the index first)
sudo updatedb
locate nginx.conf
# Which binary will run, and where is everything for a package
which python3
whereis nginx
Milestone 5: How to View File Contents and Follow Logs
Bash
cat /etc/hosts
less /var/log/syslog # q quits, /pattern searches
head -n 20 /var/log/nginx/access.log
tail -n 50 /var/log/nginx/error.log
# Follow a log live; -F survives log rotation
tail -F -n 100 /var/log/app/application.log
file /bin/bash # identify the file type
stat /etc/hosts # inode, size, timestamps, mode
Milestone 6: How to Check Disk Space with df and du
Bash
df -h
# Filesystem Size Used Avail Use% Mounted on
# /dev/xvda1 20G 12G 7.5G 62% /
df -i # inode usage, full inodes also block writes
du -sh /var/log/
# Biggest directories under /var, same filesystem only
sudo du -xh --max-depth=1 /var | sort -rh | head -10
# Biggest log files
sudo find /var/log -type f -exec du -h {} + | sort -rh | head -10
Tip

If df -h shows free space but writes still fail, run df -i. A filesystem can run out of inodes before it runs out of bytes.

Bash
# Symbolic link: a pointer to a path
sudo ln -s /opt/app/current/bin/app /usr/local/bin/app
# Repoint to a new release; -n avoids nesting inside a linked directory
sudo ln -sfn /opt/app/v2.0/bin/app /usr/local/bin/app
# Hard link: a second name for the same inode (same filesystem only)
ln /etc/hosts /tmp/hosts-hardlink
readlink -f /usr/local/bin/app # resolve the final target
# Find broken symlinks
find /usr/local/bin -xtype l

Production Best Practices & Common Pitfalls

Treat the filesystem layout as a contract: put each kind of data in its standard location so tools, backups, and teammates can find it.

  1. Use absolute paths in cron, systemd, CI, and Dockerfiles.
  2. Store persistent application data under /var/lib or a dedicated mount, never /tmp.
  3. Point a stable path such as /opt/app/current at the active release and switch it with ln -sfn.
  4. Quote every variable and use ${VAR:?} before any recursive delete.
  5. Check df -h and df -i first when anything fails to write.
Mistake Problem Fix
Relative paths in cron Wrong working directory Use absolute paths
rm -rf $VAR/ Empty variable deletes / Quote and use ${VAR:?}
Storing data in /tmp Cleared on reboot or by cleanup timers Use /var/lib or a mounted volume
Editing files in /proc by hand Changes vanish on reboot Use sysctl -w, persist in /etc/sysctl.d/
Assuming cron has your PATH Binary not found Set PATH in the crontab or use full paths
Remember

/proc and /sys are virtual. Changes made with sysctl -w are lost on reboot, so persist them in a file under /etc/sysctl.d/ and load it with sudo sysctl --system.

Quick Reference & Troubleshooting Commands

Command Description
pwd Print the current directory
ls -lh DIR Long listing with readable sizes
find DIR -name "PATTERN" Search by name
tail -F FILE Follow a log across rotation
df -h and df -i Disk space and inode usage
du -xh --max-depth=1 DIR Size of each subdirectory
readlink -f LINK Resolve a symlink to its final target
Symptom First command What to look for
Cannot write files df -h and df -i 100% in Use% or IUse%
Cannot find a file find / -name NAME 2>/dev/null A matching path in the output
Unsure which binary runs which -a COMMAND Full path, and duplicates earlier in PATH
File exists but app cannot read it namei -l /full/path A parent directory missing x
Symlink does not work readlink -f LINK Target path that does not exist
Tip

ls -lh is the most useful listing in production. It shows mode, owner, size, and modification time, which is everything you need to diagnose a file issue.

Resources

Explore More in Linux Fundamentals and File System

All 4 Topics

Frequently Asked Questions

Is Navigating the Linux Filesystem and FHS free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Navigating the Linux Filesystem and FHS topic cover?

Learn the Linux Filesystem Hierarchy Standard, absolute vs relative paths, and the ls, find, du, and ln commands every production server needs.

Found a mistake, an outdated step or a broken link?