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, andpwdusing the flags that matter - Create, copy, move, and delete files safely
- Find files with
find,locate, andwhich - Read logs with
less,head, andtail - Check disk usage with
dfanddu, 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.
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.
/etc/nginx/nginx.conf/home/rahul/.ssh/id_ed25519 # Relative: depends on the current directory./deploy.sh../config/app.yamllogs/error.logCommon MistakeRelative 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.
cat /proc/1/cmdline | tr '\0' ' ' # command that started PID 1ls -l /proc/$$/fd # open file descriptors of this shellcat /proc/meminfo # live memory statisticscat /proc/sys/net/ipv4/ip_forward # current kernel parameter valueDetailed Step-by-Step Practical Lab
Milestone 1: How to Navigate with cd, pwd, and ls
pwd# /home/rahul cd /etcls -la | head -30 # List another directory without leavingls -la /var/log/ cd ~ # home directory (same as plain cd)cd /etccd - # jump back to the previous directory# /home/rahulMilestone 2: How to List Files with Useful ls Flags
ls -lh /var/log/ # long format, human-readable sizesls -la ~ # include hidden dotfilesls -lt /var/log/ # newest modification firstls -ltr /var/log/ # newest last, easy to read at the bottomls -R /etc/ssh/ # recursive listingls -d /etc/*/ # directories onlyMilestone 3: How to Create, Copy, Move, and Delete Files
mkdir -p /tmp/lab/configs/nginx # -p creates parent directoriestouch /tmp/lab/app.logtouch /tmp/lab/{file1,file2,file3}.txt # brace expansion makes three files cp /etc/hosts /tmp/lab/hosts.backupcp -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.txtrm -r /tmp/lab/ssh-backupGuard variables before using them in a delete. The :? form aborts the script if the variable is empty or unset:
DIRNAME="/tmp/lab"rm -rf "${DIRNAME:?DIRNAME is not set}/"Security
rm -rf $DIRNAME/with an empty variable becomesrm -rf /. Always quote variables, use${VAR:?}, and runlson the target first.
Milestone 4: How to Find Files with find and locate
# By namefind /etc -name "nginx.conf"find /var/log -iname "*.log" # case insensitive # By time and sizefind /var/log -type f -mtime -1 # changed in the last 24 hoursfind / -xdev -type f -size +100M 2>/dev/null # By permissionfind /home -name ".ssh" -type d -perm 700 # Preview first, then deletefind /tmp -name "*.tmp" -mtime +7 -printfind /tmp -name "*.tmp" -mtime +7 -delete # Index-based search (refresh the index first)sudo updatedblocate nginx.conf # Which binary will run, and where is everything for a packagewhich python3whereis nginxMilestone 5: How to View File Contents and Follow Logs
cat /etc/hostsless /var/log/syslog # q quits, /pattern searcheshead -n 20 /var/log/nginx/access.logtail -n 50 /var/log/nginx/error.log # Follow a log live; -F survives log rotationtail -F -n 100 /var/log/app/application.log file /bin/bash # identify the file typestat /etc/hosts # inode, size, timestamps, modeMilestone 6: How to Check Disk Space with df and du
df -h# Filesystem Size Used Avail Use% Mounted on# /dev/xvda1 20G 12G 7.5G 62% / df -i # inode usage, full inodes also block writesdu -sh /var/log/ # Biggest directories under /var, same filesystem onlysudo du -xh --max-depth=1 /var | sort -rh | head -10 # Biggest log filessudo find /var/log -type f -exec du -h {} + | sort -rh | head -10TipIf
df -hshows free space but writes still fail, rundf -i. A filesystem can run out of inodes before it runs out of bytes.
Milestone 7: How to Create and Manage Symbolic and Hard Links
# Symbolic link: a pointer to a pathsudo ln -s /opt/app/current/bin/app /usr/local/bin/app # Repoint to a new release; -n avoids nesting inside a linked directorysudo 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 symlinksfind /usr/local/bin -xtype lProduction 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.
- Use absolute paths in cron, systemd, CI, and Dockerfiles.
- Store persistent application data under
/var/libor a dedicated mount, never/tmp. - Point a stable path such as
/opt/app/currentat the active release and switch it withln -sfn. - Quote every variable and use
${VAR:?}before any recursive delete. - Check
df -handdf -ifirst 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
/procand/sysare virtual. Changes made withsysctl -ware lost on reboot, so persist them in a file under/etc/sysctl.d/and load it withsudo 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 -lhis the most useful listing in production. It shows mode, owner, size, and modification time, which is everything you need to diagnose a file issue.