Disk Usage in Linux — Monitoring Storage and Filesystem Space¶
Disk space is one of the most critical resources on any Linux system. Running out of disk space can cause application failures, database crashes, Kubernetes pod failures, CI/CD pipeline errors, and even prevent a server from booting. Linux provides several powerful utilities to monitor and analyze disk usage effectively.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand disk usage concepts
- Monitor filesystem usage
- Measure directory sizes
- Identify large files
- Analyze storage consumption
- Troubleshoot full disks
- Monitor production servers
- Apply storage best practices
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Command Line Essentials
- Module 3 – Text Processing
- Module 4 Lessons 1–9
Why Learn Disk Usage?¶
Imagine it's 2:00 AM.
Your production application suddenly crashes.
Logs show:
Questions:
- Which filesystem is full?
- Which directory is consuming the space?
- Which files are the largest?
- How can you recover safely?
Every Linux administrator eventually encounters this scenario.
Understanding Disk Usage¶
Linux storage consists of:
Disk usage tools help you understand where storage is being consumed.
Filesystem Usage¶
Display filesystem usage.
Example:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 32G 15G 69% /
/dev/sdb1 500G 90G 385G 19% /data
Understanding df Output¶
| Column | Description |
|---|---|
| Filesystem | Storage device |
| Size | Total size |
| Used | Used space |
| Avail | Free space |
| Use% | Percentage used |
| Mounted on | Mount point |
Human Readable Output¶
Without:
Displays bytes.
Better:
Units:
Display Specific Filesystem Type¶
Example:
Inode Usage¶
Filesystems have two limits:
- Storage space
- Inodes
Display inode usage.
Example:
A filesystem can run out of inodes even when disk space is available.
Directory Usage¶
Use:
Example:
Human Readable¶
Display Total Size¶
Example:
Show Subdirectories¶
Example:
Find Largest Directories¶
Example:
Find Large Files¶
Find files larger than:
1 GB.
Largest Files¶
Check Current Directory¶
Display Mounted Filesystems¶
Display Block Devices¶
Disk Free Summary¶
Common Commands¶
Filesystem usage.
Directory size.
Largest directories.
Large files.
Block devices.
Mounted filesystems.
Real Production Examples¶
Check Kubernetes node storage.
Docker storage.
System logs.
Database storage.
Jenkins workspace.
Production Perspective¶
Disk monitoring is essential for:
- Linux servers
- Databases
- Docker
- Kubernetes
- CI/CD
- Backup servers
- Cloud VMs
- Log management
Regular monitoring prevents outages caused by storage exhaustion.
Hands-on Lab¶
Task 1¶
Display filesystem usage.
Task 2¶
Display filesystem types.
Task 3¶
Display inode usage.
Task 4¶
Display your home directory size.
Task 5¶
Display subdirectory sizes.
Task 6¶
Sort directories by size.
Task 7¶
Find files larger than 100 MB.
Task 8¶
Display the 10 largest files in your home directory.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
df -h | Filesystem usage | Capacity monitoring |
df -i | Inode usage | Troubleshooting |
du -sh | Directory size | Storage analysis |
find | Locate large files | Cleanup |
sort -hr | Sort by size | Reporting |
lsblk | Storage inventory | Administration |
Production Troubleshooting Scenario¶
Scenario
A Kubernetes node becomes NotReady.
Pods cannot start.
Investigation:
Findings:
- Container images consume 40 GB.
- Old logs consume 15 GB.
- Disk usage reaches 98%.
Solution:
- Remove unused container images.
- Rotate or archive old logs.
- Expand storage if required.
- Configure log rotation and monitoring.
Best Practices¶
- Monitor disk usage regularly.
- Investigate filesystems above 80% usage.
- Clean temporary files periodically.
- Rotate logs using log rotation tools.
- Monitor inode usage in addition to disk space.
- Automate storage alerts using monitoring platforms.
Common Mistakes¶
❌ Monitoring only free disk space.
✅ A filesystem may run out of inodes before storage space.
❌ Deleting application logs without understanding their purpose.
✅ Verify retention requirements before cleanup.
❌ Ignoring growth trends.
✅ Track storage usage over time to plan capacity before problems occur.
Interview Questions¶
Beginner¶
- What does
dfdisplay? - What is the difference between
dfanddu? - Why is
-hcommonly used? - Which command shows inode usage?
Intermediate¶
- Why can a filesystem report "No space left on device" even when free space exists?
- How do you identify the largest directories?
- How do you locate files larger than 1 GB?
- Why should inode usage be monitored?
Architect Level¶
- How would you design storage monitoring for hundreds of Linux servers?
- How would you investigate a filesystem that suddenly reaches 100% usage?
- What storage metrics would you collect for Kubernetes worker nodes?
Summary¶
In this lesson, you learned:
- Filesystem usage
- Directory usage
- Inode usage
- Finding large files
- Storage analysis
- Production troubleshooting
- Capacity planning
- Storage best practices
Disk usage monitoring is one of the most important operational tasks in Linux administration. Regularly monitoring filesystems, directories, and inodes helps prevent outages, improves capacity planning, and keeps production systems healthy.
Key Takeaways¶
- Use
df -hto monitor filesystem usage. - Use
du -shto measure directory sizes. - Use
df -ito monitor inode usage. - Use
findto locate large files. - Investigate filesystems before they become full.
- Automate storage monitoring and alerts for production systems.
What's Next?¶
Module 4 Summary — File Management and Permissions
Review the module, complete the mini project and assessment, then continue to Module 5 – Users and Groups.