A full disk causes applications to crash, logs to stop writing, and databases to become corrupted. This guide shows how to quickly find and remove large files.
Check Disk Usage
$df -hFilesystem Size Used Avail Use% Mounted on
/dev/vda1 25G 25G 0 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shmThe root filesystem is 100% full.
Find Large Directories
$du -sh /* 2>/dev/null | sort -rh | head -108.5G /var
6.2G /home
3.1G /usr
2.8G /optDrill down into the largest directory:
$du -sh /var/* 2>/dev/null | sort -rh | head -107.8G /var/log
512M /var/lib
128M /var/cacheFind Large Files
$find / -type f -size +100M 2>/dev/null | sort -k5 -rnOr use a more readable approach:
$find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -rh | head -20Common Disk Space Culprits
Large Log Files
$ls -lh /var/log/*.log | sort -k5 -rh | head -10Truncate a large log file (do not delete — the process may hold the file handle):
$truncate -s 0 /var/log/nginx/access.logOld Kernel Images
$apt autoremove --purgeDocker Images and Containers
$docker system df$docker system prune -aPackage Cache
$apt clean$du -sh /var/cache/apt/Journald Logs
$journalctl --disk-usage$journalctl --vacuum-size=500MSet Up Log Rotation
Prevent logs from growing unbounded:
$nano /etc/logrotate.d/myapp/var/log/myapp/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
sharedscripts
postrotate
systemctl reload myapp
endscript
}[!TIP] If the disk is completely full and you cannot write any files, use
truncate -s 0 /path/to/large/fileto free space without needing to create a new file.
