DF DU Disk Space - ryzendew/Linux-Tips-and-Tricks GitHub Wiki

DF & DU Disk Space Troubleshooting for Beginners

Table of Contents

  1. :pencil: What are df and du?
  2. :zap: DF (Disk Free) Commands
  3. :desktop: DU (Disk Usage) Commands
  4. :bulb: Common Troubleshooting Scenarios
  1. :keyboard: Quick Reference
  1. :warning: Important Notes
  1. Summary

:pencil: What are df and du?

  • df (Disk Free) shows filesystem disk space usage
  • du (Disk Usage) shows directory and file disk space usage
  • Essential tools for managing disk space and troubleshooting storage issues
  • Both commands are usually pre-installed on Linux systems

What df can do:

  • Show available disk space on all filesystems
  • Display filesystem types
  • Show inode usage
  • Help identify which partitions are full

What du can do:

  • Show disk usage of directories and files
  • Find large files and directories
  • Calculate total space used
  • Help identify what's taking up space

When to use them:

  • Disk is full or running low on space
  • Need to find what's using disk space
  • Planning storage allocation
  • Troubleshooting "no space left" errors

:zap: DF (Disk Free) Commands

Show All Filesystems

df

What this does:

  • Shows disk space usage for all mounted filesystems
  • Displays in 1K blocks (not human-readable)

Example output:

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p2  972091612 334742728 637348884  35% /
devtmpfs         32657208         0  32657208   0% /dev
tmpfs            32687116    587496  32099620   2% /dev/shm

What each column means:

  • Filesystem: Device or filesystem name
  • 1K-blocks: Total size in 1KB blocks
  • Used: Space used in 1KB blocks
  • Available: Space available in 1KB blocks
  • Use%: Percentage of space used
  • Mounted on: Mount point (where it's mounted)

Show Human-Readable Format

df -h

What this does:

  • Shows disk space in human-readable format (KB, MB, GB, TB)
  • Much easier to read than raw numbers
  • Most commonly used df command

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  928G  320G  608G  35% /
devtmpfs         32G     0   32G   0% /dev
tmpfs            32G  577M   31G   2% /dev/shm
efivarfs        128K   70K   54K  57% /sys/firmware/efi/efivars
tmpfs            13G  2.6M   13G   1% /run
/dev/nvme0n1p1  4.0G  7.5M  4.0G   1% /boot/efi
/dev/nvme3n1p1  932G  273G  659G  30% /mnt/Gaming

When to use it:

  • Quick overview of disk space
  • Daily disk space checks
  • Most common use case

Show Filesystem Types

df -T

What this does:

  • Shows filesystem type for each filesystem
  • Helps identify filesystem types (ext4, xfs, btrfs, etc.)

Example output:

Filesystem     Type     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p2 xfs      972091612 334742728 637348884  35% /
devtmpfs       devtmpfs  32657208         0  32657208   0% /dev
tmpfs          tmpfs     32687116    587496  32099620   2% /dev/shm
efivarfs       efivarfs       128        70        54  57% /sys/firmware/efi/efivars

Common filesystem types:

  • ext4 - Extended filesystem (common on Linux)
  • xfs - High-performance filesystem
  • btrfs - Copy-on-write filesystem
  • tmpfs - Temporary filesystem (RAM)
  • devtmpfs - Device filesystem
  • efivarfs - EFI variables filesystem

Show Inode Usage

df -i

What this does:

  • Shows inode usage instead of disk space
  • Inodes are file system structures (one per file/directory)
  • Useful when you have space but can't create files

Example output:

Filesystem        Inodes  IUsed     IFree IUse% Mounted on
/dev/nvme0n1p2 486283200 780415 485502785    1% /
devtmpfs         8164302   1256   8163046    1% /dev
tmpfs            8171779    897   8170882    1% /dev/shm
efivarfs               0      0         0     - /sys/firmware/efi/efivars

What each column means:

  • Inodes: Total number of inodes
  • IUsed: Inodes used
  • IFree: Inodes free
  • IUse%: Percentage of inodes used

When to use it:

  • "No space left on device" but df shows space available
  • Systems with many small files
  • Troubleshooting file creation issues

Show Specific Filesystem

df -h /dev/nvme0n1p2

What this does:

  • Shows disk space for a specific device/filesystem
  • Useful for checking a specific partition

Or by mount point:

df -h /

Shows disk space for root filesystem.


Exclude Filesystem Types

df -h -x tmpfs -x devtmpfs

What this does:

  • Excludes specified filesystem types from output
  • Useful for excluding temporary filesystems
  • Shows only "real" storage devices

Common exclusions:

  • tmpfs - Temporary filesystems
  • devtmpfs - Device filesystem
  • efivarfs - EFI variables

:desktop: DU (Disk Usage) Commands

Show Directory Size

du /path/to/directory

What this does:

  • Shows disk usage for a directory and all subdirectories
  • Displays in 1K blocks
  • Recursive (includes all subdirectories)

Example:

du /home

Show Human-Readable Format

du -h /path/to/directory

What this does:

  • Shows disk usage in human-readable format
  • Much easier to read
  • Most commonly used du command

Example:

du -h /home

Example output:

272G	/home/matt
272G	/home

Show Summary (Total Only)

du -sh /path/to/directory

What this does:

  • Shows only the total size (summary)
  • -s = summarize (single line)
  • -h = human-readable
  • Most useful for quick checks

Example:

du -sh /home

Example output:

272G	/home

When to use it:

  • Quick size check
  • Finding total size of a directory
  • Scripting and automation

Show Directory Sizes at Specific Depth

du -h --max-depth=1 /path/to/directory

What this does:

  • Shows sizes at specific depth level
  • --max-depth=1 shows only immediate subdirectories
  • Useful for finding which subdirectory is large

Example:

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

Example output:

272G	/home/matt
272G	/home

Common depth levels:

  • --max-depth=0 - Only the specified directory (same as -s)
  • --max-depth=1 - Directory and immediate subdirectories
  • --max-depth=2 - Two levels deep

Show Sizes of All Items in Directory

du -sh /path/to/directory/*

What this does:

  • Shows size of each item in a directory
  • Useful for finding which files/directories are large
  • * expands to all items in directory

Example:

du -sh /home/*

Example output:

272G	/home/matt

When to use it:

  • Finding large files/directories
  • Identifying what's taking up space
  • Quick overview of directory contents

Sort by Size

du -h /path/to/directory | sort -h

What this does:

  • Sorts output by size (human-readable)
  • Largest items appear last
  • Useful for finding biggest directories

Reverse sort (largest first):

du -h /path/to/directory | sort -hr

Example:

du -h --max-depth=1 /home | sort -hr

Find Largest Directories

du -h --max-depth=1 /path/to/directory | sort -hr | head -10

What this does:

  • Shows top 10 largest directories
  • Combines du, sort, and head
  • Very useful for troubleshooting

Example:

du -h --max-depth=1 / | sort -hr | head -10

Note: Running du on / may show permission denied errors for directories you don't have access to. This is normal. Use sudo if you need to see everything.


Exclude Specific Directories

du -h --exclude=/path/to/exclude /path/to/directory

What this does:

  • Excludes specified paths from calculation
  • Useful for excluding large directories you don't care about

Multiple exclusions:

du -h --exclude=/proc --exclude=/sys --exclude=/dev / | sort -hr | head -10

:bulb: Common Troubleshooting Scenarios

Scenario 1: Disk is Full

Problem: "No space left on device" error.

Solution:

  1. Check disk space:

    df -h
    
  2. Find largest directories:

    sudo du -h --max-depth=1 / | sort -hr | head -10
    
  3. Check specific partition:

    df -h /
    
  4. Find large files:

    find / -type f -size +1G 2>/dev/null
    

Scenario 2: Find What's Using Space

Problem: Need to identify what's taking up disk space.

Solution:

  1. Check home directory:

    du -sh ~/*
    
  2. Check specific directory:

    du -h --max-depth=1 /var | sort -hr
    
  3. Find largest files:

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

Scenario 3: Inode Exhaustion

Problem: "No space left on device" but df shows space available.

Solution:

  1. Check inode usage:

    df -i
    
  2. If inodes are 100%, find directories with many files:

    find /path -type f | wc -l
    
  3. Find directories with most files:

    find /path -type d -exec sh -c 'echo "$(find "$1" -maxdepth 1 -type f | wc -l) $1"' _ {} \; | sort -rn | head -10
    

Scenario 4: Check Specific Directory Size

Problem: Need to know size of a specific directory.

Solution:

du -sh /path/to/directory

With breakdown:

du -h --max-depth=1 /path/to/directory | sort -hr

Scenario 5: Find Large Files

Problem: Need to find large files taking up space.

Solution:

find /path -type f -size +100M -exec du -h {} + | sort -hr

Find files larger than 1GB:

find /path -type f -size +1G -exec du -h {} + | sort -hr

Scenario 6: Monitor Disk Usage Over Time

Problem: Need to track disk usage changes.

Solution:

watch -n 60 'df -h'

Updates every 60 seconds.

Or save to file:

df -h >> disk_usage.log

Scenario 7: Check Multiple Directories

Problem: Need to compare sizes of multiple directories.

Solution:

du -sh /home/* /var/* /usr/* 2>/dev/null | sort -hr

Or check specific paths:

for dir in /home /var /usr; do echo "$(du -sh $dir 2>/dev/null)"; done

:keyboard: Quick Reference

DF Commands

df                    # All filesystems (1K blocks)
df -h                 # Human-readable format
df -T                 # Show filesystem types
df -i                 # Show inode usage
df -h /               # Specific filesystem
df -h -x tmpfs        # Exclude filesystem types

DU Commands

du /path              # Directory size (1K blocks)
du -h /path           # Human-readable
du -sh /path          # Summary only
du -h --max-depth=1 /path    # One level deep
du -sh /path/*        # All items in directory
du -h /path | sort -hr       # Sorted by size

Finding Large Items

du -h --max-depth=1 / | sort -hr | head -10    # Top 10 largest
find /path -type f -size +1G                   # Files > 1GB
du -sh ~/* | sort -hr                          # Home directory items

:warning: Important Notes

Permission Denied Errors

When running du on system directories (like /), you may see permission denied errors:

du: cannot read directory '/proc/1234/fd': Permission denied

This is normal:

  • You don't have permission to read all directories
  • The command still works for directories you can access
  • Use sudo if you need to see everything (be careful!)

Suppress errors:

du -sh / 2>/dev/null

Redirects error messages to /dev/null.


Virtual Filesystems

Some filesystems shown by df are virtual:

  • /proc - Process information (not real disk)
  • /sys - System information (not real disk)
  • /dev - Device files (usually tmpfs)
  • tmpfs - Temporary filesystem (RAM)

These don't use actual disk space, so focus on real storage devices.


Symbolic Links

By default, du follows symbolic links. To exclude them:

du -h -L /path    # Follow links (default)
du -h -P /path    # Don't follow links

Summary

This guide covered:

  1. DF (Disk Free):
  • Basic usage and human-readable format
  • Filesystem types
  • Inode usage
  • Specific filesystem checks
  1. DU (Disk Usage):
  • Directory size calculation
  • Human-readable format
  • Summary mode
  • Depth control
  • Sorting and filtering
  1. Troubleshooting Scenarios:
  • Disk full errors
  • Finding large files/directories
  • Inode exhaustion
  • Monitoring disk usage
  1. Important Notes:
  • Permission denied errors
  • Virtual filesystems
  • Symbolic links

Next Steps:

  • Practice with df -h for quick disk checks
  • Use du -sh for directory sizes
  • Combine with find to locate large files
  • Set up disk monitoring scripts

For process management, see the PS Process Management Guide. For system resource monitoring, see the Free & Top System Resource Monitoring Guide.