Skip to content

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

Linux Mastery → Module 4: File Management and Permissions → Lesson 10

Difficulty: Beginner → Intermediate

Reading Time: 50 Minutes

Course Progress

Course: Linux Mastery

Module: File Management and Permissions

Lesson: 10 of 10


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:

No space left on device

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


Partition


Filesystem


Directories


Files

Disk usage tools help you understand where storage is being consumed.


Filesystem Usage

Display filesystem usage.

df -h

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:

df

Displays bytes.

Better:

df -h

Units:

K

M

G

T

Display Specific Filesystem Type

df -Th

Example:

Filesystem Type Size Used Mounted on

/dev/sda1 ext4 50G 30G /

Inode Usage

Filesystems have two limits:

  • Storage space
  • Inodes

Display inode usage.

df -i

Example:

Filesystem

Inodes

IUsed

IFree

IUse%

A filesystem can run out of inodes even when disk space is available.


Directory Usage

Use:

du

Example:

du Documents

Human Readable

du -h Documents

Display Total Size

du -sh Documents

Example:

2.3G Documents

Show Subdirectories

du -h --max-depth=1

Example:

200M Downloads

3G Videos

500M Documents

Find Largest Directories

du -sh * | sort -hr

Example:

15G backups

8G videos

2G downloads

Find Large Files

find . -type f -size +100M

Find files larger than:

1 GB.

find . -type f -size +1G

Largest Files

find . -type f -exec du -h {} + | sort -hr | head

Check Current Directory

du -sh .

Display Mounted Filesystems

findmnt

Display Block Devices

lsblk

Disk Free Summary

df -h /

Common Commands

Filesystem usage.

df -h

Directory size.

du -sh

Largest directories.

du -sh * | sort -hr

Large files.

find . -size +500M

Block devices.

lsblk

Mounted filesystems.

findmnt

Real Production Examples

Check Kubernetes node storage.

df -h

Docker storage.

du -sh /var/lib/docker

System logs.

du -sh /var/log

Database storage.

du -sh /var/lib/mysql

Jenkins workspace.

du -sh /var/lib/jenkins

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.

df -h

Task 2

Display filesystem types.

df -Th

Task 3

Display inode usage.

df -i

Task 4

Display your home directory size.

du -sh ~

Task 5

Display subdirectory sizes.

du -h --max-depth=1 ~

Task 6

Sort directories by size.

du -sh ~/* | sort -hr

Task 7

Find files larger than 100 MB.

find ~ -type f -size +100M

Task 8

Display the 10 largest files in your home directory.

find ~ -type f -exec du -h {} + | sort -hr | head -10

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:

df -h

du -sh /var/lib/containerd

du -sh /var/log

find /var/log -type f -size +500M

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

  1. What does df display?
  2. What is the difference between df and du?
  3. Why is -h commonly used?
  4. Which command shows inode usage?

Intermediate

  1. Why can a filesystem report "No space left on device" even when free space exists?
  2. How do you identify the largest directories?
  3. How do you locate files larger than 1 GB?
  4. Why should inode usage be monitored?

Architect Level

  1. How would you design storage monitoring for hundreds of Linux servers?
  2. How would you investigate a filesystem that suddenly reaches 100% usage?
  3. 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 -h to monitor filesystem usage.
  • Use du -sh to measure directory sizes.
  • Use df -i to monitor inode usage.
  • Use find to 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.