Terminal GuideTerminal Guide

df Command Guide

The df (disk free) command displays disk space usage for filesystems. Learn how to monitor storage effectively.

5 min readLast updated: 2024
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

dfShow disk usage
df -hHuman readable
df /pathSpecific path

Options

-TShow filesystem type
-iShow inode usage
-aInclude all

Filter

-t ext4Only ext4
-x tmpfsExclude tmpfs
-lLocal filesystems

Common

df -hTReadable with type
df -h --totalWith total
df -h /Root partition

Downloadable Image Preview

Failed to generate preview

Basic Usage

Running df without options shows disk usage for all mounted filesystems.

bash
df

Output columns: Filesystem, 1K-blocks, Used, Available, Use%, Mounted on.

Common Options

df Options

-hHuman-readable sizes (K, M, G)
-HHuman-readable with SI units (1000 vs 1024)
-TShow filesystem type
-iShow inode information
-aInclude pseudo filesystems
-t typeShow only specific filesystem type
-x typeExclude specific filesystem type
--totalAdd a total line

Human-Readable Output

bash
df -h

This is the most commonly used form, showing sizes in KB, MB, GB, etc.

Show Filesystem Type

bash
df -hT

Adds a Type column showing ext4, xfs, tmpfs, etc.

Check Specific Filesystem

bash
# Check specific path
df -h /home

# Check specific device
df -h /dev/sda1

Inode Usage

Inodes track files on the filesystem. You can run out of inodes even with free disk space if you have too many small files.

bash
df -hi
Info
Running out of inodes is less common but can happen with many small files. Monitor inode usage on mail servers or systems with lots of small files.

Filtering Output

Show only specific filesystem type

bash
# Show only ext4 filesystems
df -hT -t ext4

# Show only xfs filesystems
df -hT -t xfs

Exclude filesystem types

bash
# Exclude tmpfs and devtmpfs
df -h -x tmpfs -x devtmpfs

Show local filesystems only

bash
df -hl

Understanding the Output

Output Columns

FilesystemDevice name or remote filesystem
Size/1K-blocksTotal size of filesystem
UsedSpace currently used
AvailSpace available to users
Use%Percentage of space used
Mounted onMount point in the directory tree
Tip
The "Available" space might not equal Size minus Used because filesystems reserve space for the root user (typically 5%).

Practical Examples

Quick disk space check

bash
df -h /

Show total with all filesystems

bash
df -h --total

Monitor disk usage in scripts

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

# Alert if usage exceeds 80%
usage=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')
if [ $usage -gt 80 ]; then
  echo "Warning: Disk usage is $usage%"
fi

Find filesystems with high usage

bash
df -h | awk '$5 > 80 {print}'

Watch disk space in real-time

bash
watch -n 5 df -h

Export to CSV format

bash
df -h | awk 'BEGIN {OFS=","} {print $1,$2,$3,$4,$5,$6}'

Disk Space Tools

duDisk usage for directories and files
ncduInteractive disk usage analyzer
lsblkList block devices
fdisk -lList disk partitions
mountShow mounted filesystems

Find large directories with du

bash
# Find largest directories
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -10

Summary

df is essential for monitoring disk space. Key takeaways:

  • Use df -h for human-readable output
  • Use df -hT to include filesystem type
  • Use df -hi to check inode usage
  • Use df -x tmpfs to exclude pseudo filesystems
  • Combine with du to find what's using space

Related Articles