Linux Directory Tree
Understanding the purpose of the main directories is essential for navigation, troubleshooting, and system administration.
Visual Overview
/
├── bin → Essential user commands (ls, cp, mv)
├── boot → Boot loader files, Linux kernel, initrd
├── dev → Device files (disks, USB, tty)
├── etc → System configuration files
├── home → User home directories (/home/username)
├── lib → Essential shared libraries for /bin and /sbin
├── media → Mount points for removable devices (USB, CD)
├── mnt → Temporary mount point for filesystems
├── opt → Optional add-on software packages
├── proc → Virtual filesystem for processes & kernel info
├── root → Home directory for the root (superuser) account
├── run → Runtime variable data (PID files, sockets)
├── sbin → Essential system binaries (fdisk, ifconfig)
├── srv → Data for system services (e.g., web, FTP)
├── sys → Virtual filesystem for hardware & kernel
├── tmp → Temporary files (cleared at reboot)
├── usr → User programs, libraries, docs
│ ├── bin → Non-essential user binaries
│ ├── lib → Libraries for /usr/bin and /usr/sbin
│ ├── local → Locally installed software
│ └── share → Architecture-independent data
└── var → Variable data (logs, mail, caches)
├── log → Log files
├── cache → Cached data
└── spool → Print/mail spools
`/bin` – Essential User Binaries
- Contains basic commands needed by all users, even in single-user or recovery mode.
- Examples:
ls,cp,mv,cat,mkdir. - Always available, even if other parts of the system are not mounted.
`/etc` – System Configuration Files
- Stores system-wide configuration files and startup scripts.
- Examples:
/etc
├── /passwd/ # user account information
├── /fstab/ # shared libraries.
├── /ssh/sshd_config/ # documentation, icons, default configs.
Almost everything you configure in Linux happens through files here.
`/home` – User Home Directories
- Each user has a personal workspace under
/home/username. - Stores documents, downloads, configurations, and personal scripts.
- Example:
/home/amr/Documents/notes.txt. - Equivalent to
C:\Users\in Windows.
`/var` – Variable Data Files
- Contains data that changes frequently while the system is running.
- Examples:
/var/log/→ system and application logs./var/spool/→ print queues, mail spools./var/cache/→ cached files.- Useful when troubleshooting — most logs live here.
`/usr` – User System Resources
- Stores user applications, libraries, and documentation.
- Subdirectories include:
/usr/bin/→ non-essential user binaries (installed programs)./usr/lib/→ shared libraries./usr/share/→ documentation, icons, default configs.- Equivalent to “Program Files” in Windows, but better organized.
In summary:
/→ the root of everything./bin,/sbin,/lib→ core system utilities and libraries./etc→ the brain (configurations)./home→ users’ personal space./var→ logs and dynamic data./usr→ applications and shared resources.- Virtual filesystems like
/procand/sysdon’t contain “real” files but expose system and kernel info.
Absolute vs Relative Paths
In Linux, every file and directory has a path — a unique location in the filesystem. When you use commands like cd, cp, or ls, you need to specify paths. There are two main types: absolute and relative.
Absolute Path
An absolute path starts from the root directory / and describes the full location of a file or directory.
- Always begins with
/. - Works from _anywhere_ in the system.
Example:
cd /home/amr/Documents
This command takes you to the Documents folder inside user _amr_’s home directory, no matter where you currently are.
Relative Path
A relative path describes a location relative to your current working directory.
- Does not start with
/. - Depends on where you are right now (
pwd).
Example:
If you are in /home/amr:
cd Documents
takes you to /home/amr/Documents.
📌 Special Notations
.→ current directory
cd .
(stays in the same place)
..→ parent directory
cd ..
(goes one level up)
~→ home directory of the current user- (goes directly to
/home/username)
cd ~
Quick Comparison
| Type | Example | Meaning |
|---|---|---|
| Absolute Path | /bin/test | Always points to the same file |
| Relative Path | ../Documents/notes.txt | Depends on where you are (pwd) |
In short:
- Use absolute paths for precision and scripts.
- Use relative paths for convenience when working interactively.
Mounting Drives and Partitions
In Linux, drives and partitions are not automatically assigned drive letters (like C: or D: in Windows). Instead, they are mounted into the single directory tree. Mounting means making the contents of a storage device (partition, USB, CD, network share) accessible under a specific directory.
Key Concepts
- Device files → Stored in
/dev/(e.g.,/dev/sda1,/dev/sdb). sda= first disk,sdb= second disk.- Numbers (
sda1,sda2) = partitions. - Mount point → A directory where the device is attached.
- Example:
/mnt/usbor/media/username/USB_DRIVE. - Unmounting → Safely detaching the device so data isn’t lost.
Mounting a Drive Manually
- Create a mount point:
sudo mkdir /mnt/usb
- Mount the device:
sudo mount /dev/sdb1 /mnt/usb
- Access files:
ls /mnt/usb
- Unmount when done:
sudo umount /mnt/usb
⚙️ Viewing Mounted Drives
- Show all mounted filesystems:
mount
- Or use the modern command:
lsblk
- Check disk usage:
df -h
🛠️ Auto-Mount at Boot
To mount a drive automatically at startup, you edit / etc/fstab. Example entry:
/dev/sdb1 /mnt/data ext4 defaults 0 2
/dev/sdb1→ the partition/mnt/data→ mount pointext4→ filesystem typedefaults→ options0 2→ backup and check settings
- Be careful: mistakes in
/ etc/fstabcan prevent Linux from booting.
Summary
- mount → attach a drive to the filesystem.
- umount → detach safely.
- lsblk / df -h → check drives and usage.
- / etc/fstab → configure permanent mounts.
Disk Usage & Monitoring (df, du, free, top)
Monitoring disk and memory usage is crucial for system performance, troubleshooting, and ensuring you don’t run out of resources. Linux provides several built-in commands for this.
`df` – Disk Free Space
Shows the available and used disk space on mounted filesystems.
- Basic usage:
- Human-readable format:
df
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
tmpfs 2.0G 2.0M 2.0G 1% /run
`du` – Disk Usage per Directory
Shows how much space directories and files consume.
- Check size of current folder:
du -sh .
- Check size of subdirectories:
du -sh *
- Useful for finding large files/folders.
`free` – Memory Usage
Displays memory (RAM and swap) usage.
- Basic usage:
free
- Human-readable format:
free -h
Example:
total used free shared buff/cache available
Mem: 16G 5G 7G 1G 4G 10G
Swap: 2G 0B 2G
`top` – Live Resource Monitor
Shows real-time CPU, memory, and process usage.
- Run:
top
- Press inside
top: q→ quitM→ sort by memory usageP→ sort by CPU usage- Alternative:
htop(more user-friendly, if installed).
Summary
- df -h → check overall disk usage.
- *du -sh ** → check folder sizes.
- free -h → check memory usage.
- top / htop → monitor live system performance.
With these tools, you can easily find space hogs, monitor memory leaks, and keep your system healthy.