Linux has a standardized directory structure. Understanding it helps you navigate any Linux system and know where to find (or put) things.
The Root of Everything
Everything starts at / (root). Unlike Windows with drive letters (C:, D:), Linux has a single unified tree.
/
├── bin
├── boot
├── dev
├── etc
├── home
├── lib
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── srv
├── sys
├── tmp
├── usr
└── var
Directory Breakdown
/bin - Essential Binaries
Basic commands needed for single-user mode and system recovery:
1
2
|
ls /bin
# ls, cp, mv, rm, cat, echo, bash...
|
/sbin - System Binaries
Administrative commands (typically need root):
1
2
|
ls /sbin
# fdisk, mkfs, iptables, reboot...
|
/etc - Configuration Files
System-wide configuration:
1
2
3
4
5
6
7
8
9
|
/etc/
├── passwd # User accounts
├── shadow # Password hashes
├── group # Group definitions
├── hosts # Static hostname mapping
├── fstab # Filesystem mount table
├── ssh/ # SSH configuration
├── nginx/ # Nginx configuration
└── systemd/ # Systemd units
|
Remember: /etc = “Editable Text Configuration”
/home - User Home Directories
Each user gets a directory:
1
2
3
4
5
6
7
|
/home/
├── alice/
│ ├── Documents/
│ ├── Downloads/
│ └── .bashrc
└── bob/
└── ...
|
Your home is ~ or $HOME.
/root - Root User’s Home
The superuser’s home directory (not in /home):
1
2
3
|
/root/
├── .bashrc
└── .ssh/
|
/var - Variable Data
Data that changes during operation:
1
2
3
4
5
6
7
8
9
10
11
12
|
/var/
├── log/ # System and application logs
│ ├── syslog
│ ├── auth.log
│ └── nginx/
├── cache/ # Application caches
├── lib/ # State information
│ ├── docker/
│ └── mysql/
├── mail/ # User mailboxes
├── spool/ # Print queues, cron jobs
└── www/ # Web server files (on some systems)
|
/tmp - Temporary Files
Temporary storage, often cleared on reboot:
1
2
3
4
5
6
|
# Create temp file
mktemp
# /tmp/tmp.Abc123
# Or use for scripts
cp data.txt /tmp/data_backup.txt
|
/usr - User Programs
Secondary hierarchy for user programs:
1
2
3
4
5
6
7
8
9
10
11
|
/usr/
├── bin/ # User commands
├── sbin/ # Admin commands
├── lib/ # Libraries
├── local/ # Locally installed software
│ ├── bin/
│ └── lib/
├── share/ # Architecture-independent data
│ ├── doc/
│ └── man/
└── src/ # Source code
|
Modern note: On many systems, /bin is symlinked to /usr/bin.
/opt - Optional Software
Third-party applications:
1
2
3
4
|
/opt/
├── google/
│ └── chrome/
└── slack/
|
/dev - Device Files
Hardware and pseudo-devices:
1
2
3
4
5
6
7
8
|
/dev/
├── sda # First hard drive
├── sda1 # First partition
├── tty # Terminals
├── null # Discard output
├── zero # Endless zeros
├── random # Random data
└── urandom # Non-blocking random
|
1
2
3
4
5
|
# Discard output
command > /dev/null
# Create 1MB file of zeros
dd if=/dev/zero of=file.bin bs=1M count=1
|
Virtual filesystem for kernel and process info:
1
2
3
4
5
6
7
8
9
|
/proc/
├── 1/ # Process ID 1 (init)
│ ├── cmdline # Command line
│ ├── status # Process status
│ └── fd/ # File descriptors
├── cpuinfo # CPU information
├── meminfo # Memory information
├── loadavg # Load average
└── version # Kernel version
|
1
2
3
4
5
6
7
8
|
# Check CPU
cat /proc/cpuinfo
# Check memory
cat /proc/meminfo
# Check kernel version
cat /proc/version
|
Kernel device and driver info:
1
2
3
4
5
|
/sys/
├── block/ # Block devices
├── class/ # Device classes
├── devices/ # All devices
└── fs/ # Filesystems
|
/boot - Boot Files
Kernel and bootloader:
1
2
3
4
|
/boot/
├── vmlinuz-* # Linux kernel
├── initrd.img-* # Initial ramdisk
└── grub/ # GRUB bootloader
|
/lib - Essential Libraries
Libraries for binaries in /bin and /sbin:
1
2
3
4
|
/lib/
├── x86_64-linux-gnu/ # Architecture-specific
├── modules/ # Kernel modules
└── systemd/ # Systemd components
|
1
2
3
4
5
6
|
/media/ # Removable media (USB, CD)
├── usb-drive/
└── cdrom/
/mnt/ # Temporary mounts
└── backup-drive/
|
/srv - Service Data
Data for services provided by the system:
1
2
3
4
|
/srv/
├── www/ # Web server
├── ftp/ # FTP server
└── git/ # Git repositories
|
/run - Runtime Data
Runtime data since last boot:
1
2
3
4
|
/run/
├── user/ # Per-user runtime
├── lock/ # Lock files
└── docker.sock # Docker socket
|
Finding Things
locate - Fast File Search
1
2
3
4
5
|
# Update database first
sudo updatedb
# Find files
locate nginx.conf
|
find - Powerful Search
1
2
3
4
5
6
7
8
|
# Find by name
find /etc -name "*.conf"
# Find by type
find /var/log -type f -name "*.log"
# Find by size
find / -size +100M
|
which / whereis - Find Commands
1
2
3
4
5
|
which python
# /usr/bin/python
whereis nginx
# nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
|
Quick Reference
| Directory |
Purpose |
/ |
Root of filesystem |
/bin |
Essential commands |
/etc |
Configuration files |
/home |
User home directories |
/var |
Variable data (logs, cache) |
/tmp |
Temporary files |
/usr |
User programs |
/opt |
Third-party software |
/dev |
Device files |
/proc |
Process information |
Understanding this hierarchy makes Linux predictable. Configuration in /etc, logs in /var/log, your stuff in /home. Once you know the pattern, any Linux system feels familiar.
Comments