Overview¶
Linux provides built-in utilities to monitor disk usage and storage consumption. The most commonly used commands are:
-
du→ Disk usage of files and directories -
df→ Disk space usage of file systems
These commands are essential for:
-
System monitoring
-
Storage management
-
Troubleshooting disk-related issues
du — Disk Usage¶
Description¶
du (Disk Usage) estimates how much space files and directories consume.
Basic Usage¶
Explanation
Displays disk usage of the current directory and its subdirectories (in bytes by default).
Human Readable Summary¶
Explanation
-
-s→ summarize total size per item -
-h→ human-readable format (KB, MB, GB) -
*→ applies to all files/directories in current location
Example Output¶
Show Total Usage¶
Explanation
-c→ adds a total at the end
Example Output¶
Common du Options¶
| Option | Description |
|---|---|
-s |
Summarize |
-h |
Human readable |
-c |
Show total |
-a |
Include files (not just directories) |
Practical Examples¶
Check current directory size¶
Find large directories¶
Explanation
Shows size of directories up to one level deep.
df — Disk Filesystem Usage¶
Description¶
df (Disk Free) reports available and used disk space on file systems.
Basic Usage¶
Explanation
Displays disk usage in blocks for all mounted file systems.
Human Readable Output¶
Explanation
-
Converts sizes into KB, MB, GB
-
Easier to interpret storage usage
Example Output¶
Filter by File System Type¶
Explanation
-
-t→ specify file system type -
Shows only selected types (e.g., ext4, ext3)
Common df Options¶
| Option | Description |
|---|---|
-h |
Human readable |
-t |
Filter by file system |
-a |
Show all file systems |
Practical Examples¶
Check root partition usage¶
Check specific filesystem¶
Difference Between du and df¶
| Feature | du | df |
|---|---|---|
| Purpose | File/directory size | Filesystem usage |
| Scope | Specific paths | Entire disk partitions |
| Output | File-level details | Disk-level summary |
Important Notes¶
-
duhelps find which files consume space -
dfhelps check overall disk capacity -
Use both together for effective disk management
Summary Table¶
| Command | Purpose |
|---|---|
du |
Check file/directory usage |
du -sh * |
Summarized human-readable usage |
du -shc * |
Include total usage |
df |
Show disk filesystem usage |
df -h |
Human-readable disk usage |
df -ht ext4 |
Filter by filesystem |
Conclusion¶
The du and df commands are essential tools for:
-
Monitoring storage usage
-
Identifying large files/directories
-
Managing disk space efficiently
Understanding these commands helps maintain system performance and avoid storage-related issues.