📊 DF Command

Display Filesystem Disk Space Usage

Overview

The df command (disk free) reports filesystem disk space usage across all mounted filesystems. It's one of the most fundamental tools for system administrators to monitor available storage, identify full filesystems, and plan capacity. Unlike du which reports directory usage, df provides a filesystem-level view showing total space, used space, available space, and mount points.

1Display Basic Filesystem Information

$ df
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 51474912 28891204 20232396 59% / tmpfs 4028928 12844 4016084 1% /dev/shm /dev/sdb1 103929344 45123456 53461632 46% /data /dev/sdc1 206726144 155234567 40802567 80% /backup
Explanation: The basic df command shows disk usage in 1K blocks:
  • Filesystem: Device name (e.g., /dev/sda1) or virtual filesystem
  • 1K-blocks: Total size in 1024-byte blocks
  • Used: Space currently in use
  • Available: Space available to non-root users
  • Use%: Percentage of space used
  • Mounted on: Mount point directory
📝 Note: Numbers in 1K blocks can be hard to read. That's why the -h option (human-readable) is almost always preferred.

2Display Human-Readable Format

$ df -h
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 28G 20G 59% / tmpfs 3.9G 13M 3.9G 1% /dev/shm /dev/sdb1 100G 44G 52G 46% /data /dev/sdc1 198G 149G 40G 80% /backup
Explanation: The -h (human-readable) option displays sizes in K, M, G, T format:
  • Automatically selects appropriate unit (KB, MB, GB, TB)
  • Much easier to read and understand at a glance
  • Uses 1024-based units (1K = 1024 bytes, 1M = 1024K, etc.)
  • This is the most commonly used df format
💡 Tip: Most system administrators create an alias: alias df='df -h' in their .bashrc so df always shows human-readable output.

3Show Only Specific Filesystem Type

$ df -h -t ext4
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 28G 20G 59% / /dev/sdb1 100G 44G 52G 46% /data
Explanation: The -t option filters output to show only specific filesystem types:
  • -t ext4 - Shows only ext4 filesystems
  • -t xfs - Shows only XFS filesystems
  • -t btrfs - Shows only Btrfs filesystems
  • -t nfs - Shows only NFS mounts
This is useful when you want to focus on actual disk storage and ignore virtual/temporary filesystems.
💡 Tip: You can specify multiple types: df -h -t ext4 -t xfs shows both ext4 and XFS filesystems.

3Exclude Specific Filesystem Types

$ df -h -x tmpfs -x devtmpfs
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 28G 20G 59% / /dev/sdb1 100G 44G 52G 46% /data /dev/sdc1 198G 149G 40G 80% /backup
Explanation: The -x option excludes filesystem types from output:
  • -x tmpfs - Excludes tmpfs (RAM-based temporary storage)
  • -x devtmpfs - Excludes devtmpfs (device filesystem)
  • Removes clutter from virtual/pseudo filesystems
  • Focuses on real disk-backed storage
Common filesystems to exclude: tmpfs, devtmpfs, squashfs, overlay, cgroup
💡 Tip: Create an alias for clean output: alias dfr='df -h -x tmpfs -x devtmpfs -x squashfs'

5Show Inode Usage Instead of Block Usage

$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 3276800 421567 2855233 13% / tmpfs 1007232 842 1006390 1% /dev/shm /dev/sdb1 6553600 892345 5661255 14% /data /dev/sdc1 13107200 8234567 4872633 63% /backup
Explanation: The -i option shows inode information instead of block usage:
  • Inodes: Data structures that store file metadata (one per file/directory)
  • IUsed: Number of inodes currently used
  • IFree: Number of inodes available
  • IUse%: Percentage of inodes used
Why this matters: A filesystem can run out of inodes even if disk space remains. This typically happens with millions of tiny files (mail servers, cache directories, log files).
⚠️ Warning: If IUse% reaches 100%, you cannot create new files even if disk space is available! This is a common issue that catches people by surprise.

6Show Information for Specific Filesystem

$ df -h /data
Filesystem Size Used Avail Use% Mounted on /dev/sdb1 100G 44G 52G 46% /data
Explanation: You can check a specific filesystem by providing its mount point:
  • df -h /data - Shows only /data filesystem
  • df -h /home - Shows only /home filesystem
  • df -h / - Shows only root filesystem
This is useful in scripts or when you want to focus on a particular filesystem without the clutter of all mounts.
$ df -h /data /backup
Filesystem Size Used Avail Use% Mounted on /dev/sdb1 100G 44G 52G 46% /data /dev/sdc1 198G 149G 40G 80% /backup
You can specify multiple mount points to see several specific filesystems.

7Display Total Space Summary

$ df -h --total
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 28G 20G 59% / tmpfs 3.9G 13M 3.9G 1% /dev/shm /dev/sdb1 100G 44G 52G 46% /data /dev/sdc1 198G 149G 40G 80% /backup total 352G 221G 116G 66% -
Explanation: The --total option adds a summary line showing aggregate totals:
  • Sums all Size, Used, and Available columns
  • Calculates overall Use% across all filesystems
  • Provides quick overview of total storage situation
  • Useful for capacity planning and reporting
💡 Tip: Combine with exclusions for accurate totals: df -h --total -x tmpfs -x devtmpfs to get totals of only real disk storage.

8Show Filesystem Type in Output

$ df -hT
Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 50G 28G 20G 59% / tmpfs tmpfs 3.9G 13M 3.9G 1% /dev/shm /dev/sdb1 ext4 100G 44G 52G 46% /data /dev/sdc1 xfs 198G 149G 40G 80% /backup /dev/sdd1 btrfs 500G 324G 176G 65% /archive
Explanation: The -T option adds a Type column showing the filesystem type:
  • ext4: Fourth extended filesystem (most common Linux FS)
  • xfs: High-performance 64-bit journaling filesystem
  • btrfs: B-tree filesystem with advanced features (snapshots, etc.)
  • tmpfs: RAM-based temporary filesystem
  • nfs: Network File System
  • vfat/ntfs: Windows filesystems
This helps identify what kind of filesystem you're dealing with, which affects features, performance, and troubleshooting approaches.

9Monitor Specific Filesystems with Watch

$ watch -n 5 'df -h /data /backup'
Every 5.0s: df -h /data /backup Filesystem Size Used Avail Use% Mounted on /dev/sdb1 100G 44G 52G 46% /data /dev/sdc1 198G 149G 40G 80% /backup
Explanation: Using watch with df creates a real-time monitor:
  • watch -n 5 - Runs command every 5 seconds
  • Shows updates as space usage changes
  • Useful for monitoring during large file operations
  • Press Ctrl+C to exit the watch loop
💡 Tip: For critical filesystem monitoring during backups or large transfers: watch -n 2 'df -h | grep -E "(Filesystem|/data|/backup)"'

10Alert When Filesystem Usage Exceeds Threshold

$ df -h | awk '+$5 >= 80 {print $0}'
Filesystem Size Used Avail Use% Mounted on /dev/sdc1 198G 149G 40G 80% /backup /dev/sde1 1.0T 892G 133G 88% /archive
Explanation: This combines df with awk to find filesystems over 80% full:
  • +$5 - Converts the Use% field to a number (removing %)
  • >= 80 - Checks if usage is 80% or higher
  • {print $0} - Prints the entire line if condition is true
This is essential for creating monitoring scripts and alerting systems.
#!/bin/bash # Complete monitoring script THRESHOLD=80 df -h | awk -v threshold=$THRESHOLD ' NR==1 {print; next} # Print header +$5 >= threshold { print $0 system("echo \"Warning: " $6 " is at " $5 "\" | mail -s \"Disk Alert\" admin@example.com") } '
Production monitoring script:
  • Checks all filesystems against threshold
  • Sends email alerts for filesystems over threshold
  • Can be run via cron (e.g., hourly)
  • Easily adjustable threshold value
💡 Tip: Add to crontab for automatic monitoring: 0 * * * * /usr/local/bin/check-disk-space.sh (runs hourly)

📚 Common DF Options

Option Description Example Output Change
-h Human-readable (KB, MB, GB) 50G instead of 52428800
-H Human-readable (1000-based instead of 1024) Shows 54GB instead of 50GiB
-T Show filesystem type Adds Type column (ext4, xfs, etc.)
-i Show inode information Shows inode counts instead of blocks
-t TYPE Show only specific filesystem type Only ext4 filesystems
-x TYPE Exclude specific filesystem type Hides tmpfs filesystems
--total Add totals row at bottom Shows sum of all filesystems
-a Include dummy/pseudo filesystems Shows proc, sysfs, cgroup, etc.
-l Local filesystems only Excludes NFS and other network mounts
--output Custom column selection Choose specific columns to display

🔧 Practical Use Cases

Quick Health Check:
$ df -h | grep -vE '^(tmpfs|udev|devtmpfs)'
Shows only real disks, excluding virtual filesystems.
Find Filesystem for a File:
$ df -h /path/to/somefile
Shows which filesystem contains the specified file or directory.
JSON Output for Scripts:
$ df --output=source,size,used,avail,pcent,target -h | tail -n +2 | awk '{print "{\"device\":\""$1"\",\"size\":\""$2"\",\"used\":\""$3"\",\"avail\":\""$4"\",\"use\":\""$5"\",\"mount\":\""$6"\"}"}'
Creates structured output for parsing in automation scripts.
Compare with du for Discrepancies:
$ df -h /data && du -sh /data
If numbers differ significantly, you may have deleted files still held open by processes.

🎯 Understanding the Numbers

Why doesn't Used + Available = Size?
Most filesystems reserve 5% of space for root user to prevent system failures if users fill the disk. This reserved space is included in Size but not in Available for normal users.

To see reserved space: tune2fs -l /dev/sda1 | grep "Reserved block count" (for ext4)
Dealing with "Stale file handle" errors:
If df shows errors for NFS mounts, the remote server may be unreachable:
  • Check network connectivity: ping nfs-server
  • Check NFS service: systemctl status nfs-client
  • Force unmount if needed: umount -f /mnt/nfs
⚠️ Common Gotchas:
  • Deleted but open files: If a process has a deleted file open, the space won't be freed until the process closes the file or terminates. Check with: lsof | grep deleted
  • Hidden mount points: If a directory has files in it before a filesystem is mounted over it, those files are hidden but still consume space.
  • Snapshot/copy-on-write filesystems: Btrfs and ZFS snapshots can make df output confusing because snapshots share blocks with the original data.

💻 Combining df with Other Commands

# Show largest files on nearly-full filesystem $ df -h | grep ' 9[0-9]%' | awk '{print $6}' | xargs -I {} find {} -type f -size +100M
Finds filesystems over 90% full, then locates large files (>100MB) in those filesystems.
# Email alert if any filesystem exceeds 85% $ df -h | awk '+$5 >= 85 {system("echo Filesystem "$6" is at "$5" | mail -s \"ALERT: Disk Space\" admin@example.com")}'
Automated alerting for disk space issues.
# Show filesystems sorted by usage percentage $ df -h | tail -n +2 | sort -k5 -nr
Displays filesystems ordered from most to least full (excluding header).
💡 Pro Tips for System Administrators:
  • Always use df -h for readability
  • Check both block usage (df -h) and inode usage (df -i) when troubleshooting "no space" errors
  • Set up monitoring alerts at 80% threshold, with critical alerts at 90%
  • For NFS mounts, use df -h -l to show only local filesystems (faster, avoids network delays)
  • Remember that df shows filesystem-level view; use du to investigate directory-level usage
  • Include df -h output in system health reports and runbooks