Sagar.BlogArticle
All posts
All posts
Linux

The Linux Filesystem: Where Everything Lives

Learn the unified Linux directory tree — /home, /etc, /var, /dev, /proc and more — and understand why everything in Linux is a file.

January 5, 20258 min read
LinuxFilesystemBeginners

One of the first things that confuses Windows users switching to Linux is the directory structure. There's no C:\, no drive letters — just a single tree starting from /. Once you understand this tree, navigating Linux becomes intuitive.

Everything Is One Tree

In Linux, everything starts from a single root directory: / (called "root" or "slash"). Every file, every device, every process — all live somewhere under this one tree.

Windows uses separate trees per drive (C:\, D:\). Linux has one unified tree. USB drives, network shares, even virtual system info — everything is mounted somewhere under /.

Essential Directories

The Linux Directory Tree

DirectoryPurposeExamples
/Root — top of everythingStarting point
/homeUser home directories/home/sagar, /home/john
/rootRoot user's homeOnly accessible by root
/etcSystem configuration files/etc/passwd, /etc/nginx/
/binEssential user binariesls, cp, cat, grep
/sbinSystem admin binariesfdisk, iptables, reboot
/usrUser programs and data/usr/bin, /usr/lib
/varVariable data (changes often)Logs, databases, cache
/tmpTemporary files (cleared on reboot)Scratch space
/devDevice files/dev/sda, /dev/null
/procProcess info (virtual)/proc/cpuinfo, /proc/meminfo
/sysSystem/kernel info (virtual)Hardware info
/bootBoot loader filesKernel, GRUB
/libShared librariesLike DLLs in Windows
/optOptional/third-party softwareCustom installs
/mediaRemovable media mount pointsUSB drives, CDs
/mntTemporary mount pointsManually mounted FSes

/home — Your Personal Space

Each user gets a personal directory under /home. This is where your documents, config files, projects, and settings live. The shortcut ~ (tilde) always points to your own home directory, regardless of who you are or where you are in the filesystem.

Hidden files (dotfiles) start with a . and store per-user settings for programs like bash, git, vim, etc.

/home/
├── sagar/           ← Your home directory (~)
│   ├── Documents/
│   ├── Downloads/
│   ├── Desktop/
│   ├── .bashrc       ← Hidden config file (note the dot)
│   ├── .ssh/         ← SSH keys and config
│   └── Projects/
└── john/
    ├── Documents/
    └── ...

/etc — Configuration Central

/etc (from "et cetera") holds system-wide configuration files — plain text files that control how services, users, networking, and the OS itself behave. You'll spend a lot of time here as a sysadmin.

/etc/
├── passwd           ← User accounts (no passwords here!)
├── shadow           ← Encrypted password hashes
├── group            ← Group definitions
├── hostname         ← System hostname
├── hosts            ← Local DNS: IP → hostname mappings
├── fstab            ← Filesystem mount table (what mounts at boot)
├── ssh/
│   └── sshd_config  ← SSH server configuration
├── nginx/
│   └── nginx.conf   ← Web server configuration
└── apt/
    └── sources.list ← Package repository URLs

/var — Variable Data

/var holds data that changes constantly while the system runs — log files growing as events happen, mail queues building up, database files being written to. If you're debugging a system problem, /var/log/ is where you look first.

/var/
├── log/             ← System logs (VERY important for debugging)
│   ├── syslog       ← General system messages
│   ├── auth.log     ← Login attempts, sudo usage
│   └── nginx/       ← Web server access/error logs
├── cache/           ← Application cache (safe to delete)
├── mail/            ← Email storage
└── tmp/             ← Temp files that survive reboots (unlike /tmp)

/dev — Everything Is a File

One of Linux's foundational principles: everything is a file — even hardware devices.

Your hard disk is a file. Your terminal is a file. There's even a file that discards everything written to it (/dev/null — the "black hole" of Linux) and one that generates infinite zeros (/dev/zero).

Common Device Files

FileWhat It Is
/dev/sdaFirst SATA/SCSI hard disk
/dev/sda1First partition on first disk
/dev/nvme0n1First NVMe SSD
/dev/nullBlack hole — discards everything written to it
/dev/zeroInfinite source of zero bytes
/dev/randomRandom number generator
/dev/ttyCurrent terminal
# Send output to the void (discard it)
some-noisy-command > /dev/null

# Discard both stdout and stderr
some-command > /dev/null 2>&1

# Generate 32 random bytes and base64-encode them (for secrets)
head -c 32 /dev/random | base64

/proc — Processes as Files

/proc is a virtual filesystem — there are no real files on disk. The kernel generates its contents on the fly when you read from it. It's a window into the live state of the running system.

cat /proc/cpuinfo              # CPU model, cores, flags
cat /proc/meminfo              # RAM usage breakdown
cat /proc/version              # Kernel version string
cat /proc/uptime               # Seconds since boot (two numbers)
ls /proc/1/                    # All info about PID 1 (systemd/init)
cat /proc/1/cmdline            # The command that started PID 1

Absolute vs Relative Paths

Path Types and Special Symbols

TypeStarts WithExampleDescription
Absolute//home/sagar/notes.txtFull path from root — works from anywhere
Relativeanything elseDocuments/notes.txtRelative to where you currently are
SymbolMeaningExample
/Root directorycd /
~Your home directorycd ~ = cd /home/sagar
.Current directory./script.sh
..Parent directory (one level up)cd ..
-Previous directorycd - (toggle)
# Absolute path — works from anywhere
ls /var/log/nginx

# Relative path — depends on where you are
ls log/nginx         # Only works if you're already in /var

# Special symbol shortcuts
cd ~                 # Go home
cd ..                # Go up one level
cd ../..             # Go up two levels
cd -                 # Go back to previous directory

Quick Check

You're debugging why a web server is failing. Which directory do you check first?

Quick Check

What does the `~` symbol represent in a Linux path?

Exercise

Explore the filesystem:

  1. Run ls / — list all the top-level directories and identify 3 that you now recognize
  2. Run ls /etc | head -20 — what kind of files do you see?
  3. Run cat /proc/cpuinfo | grep "model name" — what CPU does your machine have?
  4. Try sending output to the black hole: echo "gone forever" > /dev/null — what happens?