Linux - Disk Usage (df, du)

Monitoring disk usage is essential for maintaining system performance and preventing storage-related issues. In Linux, two of the most commonly used commands for checking disk space are df and du. Both commands give insights into storage consumption, but they serve different purposes and display information in different ways.


1. df Command (Disk Free)

The df command shows overall disk space usage for file systems. It tells you how much space is used, how much is free, and how much total space is available on each mounted file system.

Basic usage:

df -h

The -h option displays values in human-readable format (MB/GB).

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   25G   23G  52% /
tmpfs           3.9G     0  3.9G   0% /dev/shm

Key Fields:

  • Filesystem → the storage device or partition

  • Size → total size

  • Used → space currently used

  • Avail → free space available

  • Use% → percentage of used disk

  • Mounted on → where the filesystem is mounted

When to use df?

  • To check total disk space

  • To monitor disk partitions

  • To troubleshoot “disk full” issues

  • To see which partition is running out of space


2. du Command (Disk Usage)

The du command shows disk usage of files and directories. Unlike df, which shows total disk usage, du focuses on how much space specific directories or files are using.

Basic usage:

du -h /path

Show total size of a directory:

du -sh /home/user

List size of each subdirectory:

du -h /var/log

Important Options:

Option Meaning
-h Human-readable size
-s Summary (total size only)
-a Show sizes for all files
--max-depth=1 Show size of directory + subdirectories only

Example:

du -h --max-depth=1 /var

This shows which subfolder consumes the most space.

When to use du?

  • To find which folder is using too much space

  • To clean up large files or logs

  • To analyze specific directory usage


3. df vs du (Key Differences)

Feature df du
Shows total disk space ✔️
Shows usage per directory/file ✔️
Helps find full partitions ✔️
Helps find large folders ✔️
Fast ✔️ Slower (scans directories)

Both commands complement each other in disk management.


4. Useful Examples

Check disk space on all partitions

df -h

Check space consumed by current directory

du -sh .

Check which folder is filling space

du -h --max-depth=1 /

Find large files (combine du + sort)

du -ah / | sort -rh | head -20

5. Why Disk Usage Monitoring Matters?

Regularly checking disk usage helps you:

  • Prevent system crashes due to full disks

  • Identify heavy logs or large files

  • Maintain good system performance

  • Ensure efficient storage planning

  • Troubleshoot errors related to space


In Summary

  • df provides a high-level view of disk usage per filesystem.

  • du shows detailed folder and file-level disk usage.

  • Together, they help you monitor storage, clean up unnecessary data, and keep your Linux system running smoothly.

 

Understanding both commands is essential for system administrators, DevOps engineers, and anyone managing Linux environments.