df Command

The df command (disk free) displays filesystem disk space usage in Linux and Unix systems. It shows the amount of disk space used and available on mounted filesystems, making it essential for monitoring storage capacity and preventing disk space issues.

Syntax

df [options] [filesystem...]

Description

The df command displays information about filesystem disk space usage. It shows the total size, used space, available space, and usage percentage for each mounted filesystem. This information is crucial for system administration and monitoring storage capacity.

Key features:

  • Display disk space usage for all mounted filesystems
  • Show usage in various formats (blocks, human-readable)
  • Filter by filesystem type or specific paths
  • Monitor storage capacity and prevent disk full errors
  • Support for different filesystem types (ext4, xfs, btrfs, etc.)

Output Fields Explanation

  • Filesystem: Device name or filesystem identifier
  • 1K-blocks: Total size in 1024-byte blocks (default)
  • Used: Amount of space currently used
  • Available: Amount of space available for use
  • Use%: Percentage of space used
  • Mounted on: Directory where filesystem is mounted

Common Options

Option Description Example
-h Human-readable format (KB, MB, GB) df -h
-H Human-readable with powers of 1000 df -H
-T Show filesystem type df -T
-t type Show only specific filesystem type df -t ext4
-x type Exclude specific filesystem type df -x tmpfs
-i Show inode usage instead of blocks df -i
-a Include dummy filesystems df -a

Common Filesystem Types

  • ext4: Fourth extended filesystem (Linux default)
  • xfs: High-performance filesystem
  • btrfs: B-tree filesystem with advanced features
  • tmpfs: Temporary filesystem in RAM
  • proc: Process information pseudo-filesystem
  • sysfs: System information pseudo-filesystem
  • devtmpfs: Device filesystem

Sample df -h Output

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  8.5G   11G  45% /
/dev/sda2       100G   45G   50G  48% /home
tmpfs           2.0G     0  2.0G   0% /dev/shm
/dev/sdb1       500G  350G  125G  74% /var/log

Examples

Basic disk space checking

df # Show all filesystems (in blocks)
df -h # Human-readable format (KB, MB, GB)
df -H # Human-readable with powers of 1000
df -T # Include filesystem type

Display disk usage in different formats and with additional information

Check specific directories or filesystems

df /home # Check filesystem containing /home
df /var/log # Check filesystem for /var/log
df /dev/sda1 # Check specific device
df -h /tmp /var /home # Check multiple paths

Monitor disk space for specific locations or devices

Filter by filesystem type

df -t ext4 # Show only ext4 filesystems
df -t xfs # Show only XFS filesystems
df -x tmpfs # Exclude tmpfs filesystems
df -x proc -x sysfs # Exclude multiple types

Focus on specific filesystem types or exclude unwanted ones

Inode usage monitoring

df -i # Show inode usage instead of blocks
df -ih # Human-readable inode usage
df -i /var # Check inode usage for /var

Monitor inode usage to detect "no space left" issues from too many files

Continuous monitoring

watch df -h # Update every 2 seconds
watch -n 5 'df -h | grep -v tmpfs' # Update every 5 seconds, exclude tmpfs
df -h > disk_usage.log # Save to file for analysis

Monitor disk space changes over time

Scripting and automation

# Check if disk usage exceeds 80%
df -h | awk '$5 > 80 {print $0}'

# Get usage percentage for root filesystem
df -h / | awk 'NR==2 {print $5}'

# Alert if any filesystem > 90% full
df -h | awk '$5+0 > 90 {print "WARNING: " $6 " is " $5 " full"}'

Use df in scripts for automated monitoring and alerting

⚠️ Disk Space Warnings

  • 90%+ usage: Critical - immediate action needed
  • 80-90% usage: Warning - plan cleanup or expansion
  • 100% usage: System may become unstable or unusable
  • Inode exhaustion: Can cause "no space left" even with free disk space
  • Root filesystem full: Can prevent system boot or operation

💡 Tips and Best Practices

  • Use -h for readability: Much easier to interpret than raw blocks
  • Monitor regularly: Set up automated alerts for high usage
  • Check both blocks and inodes: Both can cause space issues
  • Exclude pseudo-filesystems: Use -x to filter out tmpfs, proc, etc.
  • Combine with du: Use du to find what's using space
  • Watch for sudden changes: Rapid usage increases may indicate issues

Common Use Cases

  • Daily monitoring: df -h
  • Check specific partition: df -h /var
  • Exclude temporary filesystems: df -h -x tmpfs -x devtmpfs
  • Monitor inode usage: df -ih
  • System health check: df -hT
  • Automated alerts: df -h | awk '$5+0 > 85'

See also