How to Check Disk Usage with df and du on Linux
In this tutorial, you'll learn about How to Check Disk Usage with df and du on Linux. We cover key concepts, practical examples, and best practices.
The Problem
Your Linux server is running out of disk space. Applications fail with No space left on device, log writes stop, and you need to find what is consuming the disk space quickly.
Quick Fix
Step 1: Check overall filesystem usage with df
Show disk usage for all mounted filesystems in human-readable format:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 98G 82G 12G 88% /
/dev/sdb1 500G 300G 200G 60% /data
The Use% column shows how full each filesystem is.
Step 2: Show filesystem type and inode usage
Some filesystems have free space but run out of inodes:
df -hT
df -i
Step 3: Find the largest directories with du
Scan the root directory to find top-level disk consumers:
sudo du -sh /* | sort -rh | head -10
4.5G /usr
3.2G /var
2.1G /home
1.8G /opt
Step 4: Drill down into a specific directory
Find large subdirectories under /var:
sudo du -sh /var/* | sort -rh | head -10
2.0G /var/log
800M /var/lib
500M /var/cache
Step 5: List the largest files in a directory
Find individual files over 100MB:
sudo find /var -type f -size +100M -exec ls -lh {} \; | sort -k5 -rh | head -10
-rw-r----- 1 root adm 1.2G Jun 24 10:00 /var/log/syslog.1
-rw-r--r-- 1 root root 800M Jun 23 00:00 /var/log/nginx/access.log
Step 6: Show disk usage of the current directory
Check how much space the current directory uses:
du -sh .
256M .
Alternative Solutions
Use ncdu for interactive disk analysis
Navigate directories with a terminal UI:
ncdu /var
Use du with --exclude to skip large directories
Ignore mount points or known large paths:
du -sh /* --exclude=/proc --exclude=/sys --exclude=/snap 2>/dev/null
Common Mistakes to Avoid
Using df without -h. Raw byte counts are hard to read. -h shows sizes in human format (G, M, K).
Running du on the root filesystem without excluding mounts. /proc, /sys, and /snap are pseudo-filesystems that du will descend into. Use --exclude.
Not using sudo with du. Without root permissions, du skips directories it cannot read, giving an incomplete picture of disk usage.
Pro Tips
Use du --max-depth for targeted scans. Limit directory depth to speed up scans: du -h --max-depth=2 /var shows two levels of subdirectories.
Use df -i to check inode exhaustion. Full inodes prevent file creation even with free disk space. Check with df -i and clean up many small files.
Use ncdu for interactive exploration. The ncdu tool provides a navigable terminal interface for finding large directories quickly.
Prevention
- Set up log rotation with
logrotateto prevent log files from filling the disk. - Monitor disk usage with
df -hand set alerts at 80% and 90% usage. - Use
ncdufor interactive disk usage analysis when dealing with complex directory structures.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro