Script Valley
Linux & Bash for Developers
Process Management & System MonitoringLesson 4.5

How to check disk usage in Linux with df and du

df -h output, du -sh, find by size, disk inode limits, lsof for open files, ncdu, checking what fills disk

Two Commands, Two Perspectives on Disk

df shows disk space at the filesystem level — total, used, and available for each mounted partition. du shows disk usage at the directory level — how much space a directory and its contents consume. Use both together to diagnose disk full issues.

df: Filesystem Overview

# Human-readable output
df -h

# Show only ext4 filesystems (exclude tmpfs)
df -h -t ext4

# Check inode usage (disk full errors despite free space)
df -i

du: Directory Drill-Down

# Size of current directory
du -sh .

# Size of each subdirectory
du -sh */

# Top 10 largest directories under /var
du -h /var --max-depth=2 | sort -rh | head -10

# Find files larger than 500MB anywhere
find / -size +500M -type f 2>/dev/null

# Find what process is holding an open deleted file
# (common cause of disk full even after deleting logs)
lsof | grep deleted

When Disk Is Full but du Shows Free Space

If df shows 100% but du shows plenty of space, a process is holding an open file descriptor to a deleted file. The space is not freed until the process closes it. Use lsof | grep deleted to find the culprit, then restart that process.