Linux Filesystem Hierarchy and Core Concepts¶
Before you can troubleshoot anything on Linux, you need a correct mental model of where things live and why. This article covers the Filesystem Hierarchy Standard (FHS), permissions, and the ownership model that everything else in this handbook assumes you already know.
How it works¶
Linux organizes everything as files under a single root (/) — there are no drive letters. Separate physical or logical volumes are mounted onto directories within this tree. The Filesystem Hierarchy Standard (FHS) defines what each top-level directory is for:
| Path | Purpose |
|---|---|
/bin, /sbin | Essential binaries (on modern systems, usually symlinks into /usr/bin, /usr/sbin) |
/etc | System-wide configuration files (plain text, no binaries) |
/var | Variable data: logs (/var/log), spool queues, package caches |
/opt | Third-party / self-contained application packages |
/proc, /sys | Virtual filesystems exposing kernel and process state — not real files on disk |
/home | User home directories |
/tmp | Temporary files, typically cleared on reboot |
/usr | The bulk of installed software, libraries, and documentation |
/proc and /sys are worth dwelling on: they don't consume disk space and their contents are generated on read. /proc/<pid>/ holds live information about a running process; /proc/meminfo, /proc/cpuinfo, and /proc/net/ are where tools like free, top, and (older) netstat actually get their numbers from.
Ownership and permissions¶
Every file has an owner (a user) and a group, plus three permission triplets — owner, group, others — each with read (r), write (w), and execute (x) bits.
Reading this left to right: - (regular file, as opposed to d for directory or l for symlink), then rw- (owner root can read/write), r-- (group root can only read), r-- (everyone else can only read).
Permissions are commonly set two ways:
chmod 644 file.txt # numeric form: owner=rw, group=r, other=r
chmod u+x script.sh # add execute for the owner only
chown alice:developers file.txt # change owner to alice, group to developers
The numeric form is a 3-digit octal number, one digit per triplet, where read=4, write=2, execute=1, summed: rw- = 4+2+0 = 6, r-- = 4. So 644 means owner can read/write, group and others can only read.
The sticky bit on /tmp¶
The leading 1 is the sticky bit. On a directory, it means: even though everyone can write into /tmp (the trailing 7), a user can only delete or rename files they themselves own inside it — not each other's files. Without it, /tmp being world-writable would let any user delete any other user's temp files.
Ubuntu/Debian vs. RHEL-family differences¶
| Ubuntu/Debian | RHEL/Alma/Rocky | |
|---|---|---|
| Package manager | apt, dpkg | dnf (yum on older releases), rpm |
| Default shell | dash for /bin/sh, bash interactively | bash for both |
| Firewall front-end | ufw (wraps nftables/iptables) | firewalld |
| SELinux | Not installed by default (AppArmor instead) | Enabled (Enforcing) by default |
| Config layout | Mostly the same FHS, service configs often in /etc/<service>/ | Same, but expect SELinux contexts on files |
The FHS layout itself (/etc, /var, /usr, ...) is identical — it's not a distribution-specific convention, it's a cross-distribution standard both families follow.
Practical exercise¶
- Create a test file and inspect its default permissions:
- Remove write access for your own user, then try to edit the file with a text editor and observe what happens:
- Restore write access and check the numeric permission value:
How to verify you did it correctly¶
- Step 2 should produce
bash: /home/<you>/test.txt: Permission denied(bash prints the expanded path) (or your editor's equivalent error). - After step 3,
stat -c "%a"should print644(or whatever your originalumaskproduced before you changed anything).
Common mistakes¶
- Using
chmod 777to "fix" a permission error. This makes the file writable and executable by everyone, including other users and (if network-exposed) potentially services you didn't intend to grant access. Find the actual owner/group mismatch instead —ls -landid <user>will usually show it immediately. - Confusing
/binvs/usr/bin. On modern distributions these are merged (/binis a symlink to/usr/bin), but scripts written for older systems sometimes hardcode one or the other. - Assuming
/tmpis persistent. Many distributions mount/tmpastmpfs(RAM-backed) or clear it on boot — don't store anything there you can't afford to lose.
⚠ Dangerous commands¶
chmod -R 777 /or any recursivechmod/chownon a system directory can breaksudo, SSH, and most system services outright (many daemons refuse to start if their config files are world-writable, as a security measure). Never run a recursive permission change outside a directory you're certain only contains your own application's files.rm -rf /(orrm -rf /*) is the canonical catastrophic mistake — modernrmrefuses this on the literal root by default, butrm -rf $VAR/where$VARis an empty/unset variable expands to the same thing and is not protected against.
Related articles¶
Review questions¶
- What is the difference between
/binand/usr/binon a modern Linux distribution? - Why does the sticky bit matter specifically for
/tmp? - What does
chmod 750 filegrant to the owner, the group, and everyone else? - Why is
/procdescribed as a "virtual" filesystem, and what happens if you try to check its size withdu?