Skip to content

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

du

Explanation
Displays disk usage of the current directory and its subdirectories (in bytes by default).


Human Readable Summary

du -sh *

Explanation

  • -s → summarize total size per item

  • -h → human-readable format (KB, MB, GB)

  • * → applies to all files/directories in current location

Example Output

4.0K file1.txt
12M folder1
2.5G folder2

Show Total Usage

du -shc *

Explanation

  • -c → adds a total at the end

Example Output

4.0K file1.txt
12M folder1
2.5G folder2
2.6G total

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

du -sh .

Find large directories

du -h --max-depth=1

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

df

Explanation
Displays disk usage in blocks for all mounted file systems.


Human Readable Output

df -h

Explanation

  • Converts sizes into KB, MB, GB

  • Easier to interpret storage usage

Example Output

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   20G   28G  42% /

Filter by File System Type

df -ht ext4

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

df -h /

Check specific filesystem

df -ht ext4

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

  • du helps find which files consume space

  • df helps 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.