Your deploys are failing, MySQL has stopped accepting writes, and the error staring back at you is No space left on device. A vps disk full incident feels like a catastrophe, but it is usually a ten-minute fix once you know where to look. This guide walks you through the exact order to diagnose it, free space safely, and stop it from happening again — without deleting anything you will regret.
Everything here runs on a standard Ubuntu or Debian VPS, and the same commands work on AlmaLinux and Rocky with dnf in place of apt. Run them as root or with sudo. And before you touch anything: if the server offers snapshots, take one. A full disk is a bad moment to discover your backups live on the same disk you are about to clean.
Step 1: Confirm what is actually full
Start with df, which asks the filesystem how much space is used. It is instant because it does not walk any files:
df -h
df -i
df -h shows each mounted filesystem in human-readable sizes. Note which mount is full — a full / is a different problem from a full /var or a separate data disk, and the fix depends on the answer.
df -i is the check most people skip, and it matters: it shows inode usage. Every file uses one inode, and ext4 creates a fixed number of them when the filesystem is made. A volume can be 50% full on bytes and 100% full on inodes if it holds millions of tiny files — session files, mail queues, cache objects. If df -h shows space free but your app still reports the disk as full, inodes are the first suspect. Step 8 below covers that case.
One more thing to know before you panic: on ext4, Used and Avail will not add up to Size. The filesystem reserves 5% of its blocks for root by default, so ordinary users and services hit “full” while root still has a little room left to clean up. That reserved space is a feature, not a bug — it is what lets you log in and fix the problem.
Step 2: Find the culprit with du
df tells you which filesystem is full. du tells you what is using the space. Drill down one level at a time, starting at the top:
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h
The flags do the work: -x stays on one filesystem so the scan does not wander into /proc, network mounts, or other disks; -h makes sizes readable; sort -h puts the biggest directory last, where your eye lands. Run du with sudo — without it, every directory you cannot read counts as empty and the totals come out too low.
Take the biggest directory and repeat inside it:
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h
sudo du -xh --max-depth=1 /var/log 2>/dev/null | sort -h
On a typical web VPS, /var is the heavy one. The usual suspects inside it are /var/log (web server and system logs), /var/lib/docker (images, containers, build cache), /var/lib/mysql (database data and binary logs), and package caches. Backup tarballs hiding in /root or /home are another classic — especially the backup of the backup.
Step 3: Use ncdu when you want the answer in one minute
If you expect to drill down several levels, install ncdu (NCurses Disk Usage). It scans a tree once and lets you browse the result sorted by size, instead of re-running du at every level:
sudo apt install ncdu # Debian / Ubuntu
sudo dnf install ncdu # Fedora / RHEL / AlmaLinux
sudo ncdu -x /
On a server where / is full, ncdu -x / usually pinpoints the culprit — an overgrown log, an orphaned backup, a bloated cache — in under a minute. It can delete files with d, which asks for confirmation, but on a production box it is safer to browse with ncdu and delete deliberately from the shell, where you can see exactly what you are typing.
Step 4: Hunt the biggest individual files
Sometimes the problem is not a folder full of small files but one giant file — a runaway log, a forgotten database dump, a VM image in someone’s home directory. List the biggest files directly:
sudo find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null
The -xdev flag is the important one: it keeps the search on the root filesystem. Without it, the search also walks /proc, /sys, other disks, and NFS mounts. Drop the threshold to +100M if the 500 MB search comes back empty.
Step 5: The trap — deleted files that are still holding space
Here is the one that catches experienced admins. Linux does not reclaim space from a deleted file while a process still has it open. So you rm a 12 GB log, run df -h, and nothing changes — du can no longer see the file, but df still counts its blocks.
Check for it before you start deleting things:
sudo lsof +L1
If you see a large deleted log held by nginx, php-fpm, mysqld, or journald, restart or reload that service after you have dealt with the live file properly. The restart closes the file descriptor and the space comes back immediately.
This is also why you should never rm a log file that an application is still writing to. Truncate it instead, which keeps the file (and its open descriptor) intact while emptying its contents:
sudo truncate -s 0 /var/log/nginx/access.log
Truncating is safe. Deleting a live log is how you end up with a service that silently stops logging — or a disk that stays full after you “fixed” it.
Step 6: Free space safely, in this order
Work from the least dangerous space you can recover. These steps usually free hundreds of megabytes to several gigabytes, and none of them touch your site content.
Package caches and old kernels
sudo apt clean
sudo apt autoremove --purge -y
apt clean removes cached .deb files; autoremove --purge removes packages that were installed as dependencies and are no longer needed, including old kernels. On RHEL-family systems the equivalent is sudo dnf clean all followed by sudo dnf autoremove -y. Check what autoremove plans to delete before you confirm — on a server you set up by hand, a “dependency” might be something you actually use.
The systemd journal
journalctl --disk-usage
sudo journalctl --vacuum-size=200M
sudo journalctl --vacuum-time=7d
The journal grows quietly and can reach gigabytes on a busy server. --vacuum-size keeps the newest 200 MB; --vacuum-time keeps the last 7 days. Use one or the other, not both at once. To stop it growing back, set a permanent cap in /etc/systemd/journald.conf — SystemMaxUse=200M — then restart systemd-journald.
Old snap revisions
If your server runs snaps, every revision of every snap stays on disk until you remove it:
snap list --all | awk '/disabled/{print $1, $3}' | while read name rev; do sudo snap remove "$name" --revision="$rev"; done
Temporary files
sudo systemd-tmpfiles --clean
This clears files in /tmp and /var/tmp that are older than their configured age. It is safe — that is what those directories are for — but do not rm -rf /tmp/* by hand on a running server; something may be using a file in there right now.
Step 7: Docker is probably eating your disk
If your VPS runs Docker, check it before anything else. Old images, stopped containers, and build cache can easily eat tens of gigabytes without you noticing. See exactly where it stands:
docker system df
Then reclaim the safe part:
docker system prune -f
By default, docker system prune removes stopped containers, unused networks, dangling images, and build cache — but not volumes, precisely to stop you deleting data by accident. Add -a to remove all unused images, not just dangling ones, and --volumes only when you have verified no container depends on those volumes. docker system prune -af --volumes is the nuclear option: it deletes data permanently, so run docker volume ls and check what you are about to lose first.
If you want build cache only, without touching containers or images, docker builder prune does exactly that. And if Docker is a permanent part of your stack, consider moving its data directory to a bigger disk or setting a storage-driver size limit — cleaning up after every deploy is a chore you will eventually forget. Our Laravel Docker deploy guide covers the setup that makes this a one-time decision.
Step 8: MySQL binary logs — the silent 30-day hoard
If /var/lib/mysql is the heavy directory, the culprit is often binary logs. MySQL 8.x enables binary logging by default and keeps 30 days of logs (binlog_expire_logs_seconds defaults to 2,592,000 seconds). On a busy app that is tens of gigabytes of write history you probably do not need.
Check what you are holding:
SHOW BINARY LOGS;
SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';
Then purge with SQL — never with rm. Deleting binlog files by hand breaks the binlog index and can break replicas:
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 7 DAY;
PURGE BINARY LOGS refuses to delete files a connected replica is still reading, which is exactly the safety net rm lacks. To stop the pile-up permanently, set a shorter retention. Seven days is sensible for most small setups; six hours is fine if you run a single node with no replicas and no point-in-time recovery requirement:
SET PERSIST binlog_expire_logs_seconds = 604800;
Two warnings. First, the old expire_logs_days variable was deprecated in MySQL 8.0 and removed in 8.4 — if you are on 8.4, it will error, so use binlog_expire_logs_seconds. Second, do not shorten retention if you run read replicas or rely on point-in-time recovery: in that case the logs are not waste, they are your recovery plan, and the right answer is a bigger disk.
Step 9: When it is inodes, not bytes
If df -i shows 100% inode use while df -h shows space free, you have millions of tiny files, not big ones. Count files per directory instead of bytes:
sudo find /var -xdev -printf '%h\n' 2>/dev/null | sort | uniq -c | sort -nr | head
The usual offenders are PHP session files in /var/lib/php/sessions, mail queues, and application caches that never expire. Clear the cache directory for the app in question, check that its session garbage collection is actually running (PHP’s session.gc_probability defaults mean cleanup only happens on some requests), and set a cron job to prune the directory if the app will not do it itself.
You cannot add inodes to an existing ext4 filesystem, so if this keeps recurring, the real fix is a filesystem with more inodes (created with mkfs.ext4 -N) or a bigger disk. Inode exhaustion is a design problem, not a cleanup problem.
Step 10: Stop it happening again
Freeing space is the easy half. The disk filled up silently once; without a guardrail it will do it again, probably at 3 a.m. before a launch.
Set up logrotate properly
Most logs are already managed by logrotate, but the defaults are often generous. Check that the timer is actually running:
sudo systemctl status logrotate.timer
Then give your own apps a rotation rule in /etc/logrotate.d/. A typical one for a Laravel or Nginx log:
/var/log/myapp/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
}
Seven days of compressed logs is plenty for most apps. If you need more history, ship logs off the server instead of keeping them on it — that is what the disk space is for.
Alert at 80%, not 100%
Treat 80% full as your alert threshold, not a Linux requirement. A five-line cron check is enough to start:
*/30 * * * * df -h / | awk 'NR==2 && $5+0 >= 80 {print "Disk at " $5 " on " $6}' | mail -s "Disk warning" you@example.com
Better still, use a proper monitor — Netdata, Uptime Kuma, or your VPS provider’s built-in alerts — so the warning reaches you before the disk does. If you run scheduled backups, make sure they land off the server; a backup stored on the same disk it is backing up is the most common way a “safe” server fills itself. See our automated VPS backups guide for a setup that keeps backups off the box.
Know when to resize instead
Sometimes the honest answer is that the disk is too small. If you have cleaned everything safe, capped the journal, pruned Docker, and the disk is still above 85%, resize it. Most VPS providers let you grow a disk from the panel, then you extend the filesystem — sudo growpart /dev/vda 1 followed by sudo resize2fs /dev/vda1 on ext4. Growing a disk is cheaper than the outage a full one causes.
7 mistakes that make a full disk worse
- Deleting a live log with
rm. The process keeps the file open, the space never comes back, and the app stops logging. Truncate it instead. - Running
rm -rfon a path you typed from memory. One typo and you are restoring from backup — if the backup is not on the same full disk. - Deleting MySQL binlogs with
rm. It corrupts the binlog index and can break replicas. UsePURGE BINARY LOGS. - Pruning Docker volumes blindly.
--volumesdeletes data permanently. Checkdocker volume lsfirst. - Cleaning the wrong mount. Always run
df -hfirst and confirm which filesystem is full. - Ignoring inodes. If
df -hshows space free but writes still fail, checkdf -i. - Freeing space and walking away. Without logrotate limits and an 80% alert, you will be back here next month.
Conclusion
A full VPS disk is a two-part job: diagnose first, clean second. df -h and df -i tell you what is full, du and ncdu tell you what is using it, and lsof +L1 catches the deleted-but-open trap that makes rm look broken. Clean in the safe order — package caches, journal, logs, Docker, then MySQL binlogs — and never delete a file you cannot identify. Then put the guardrails in place: logrotate limits, an alert at 80%, and backups that live off the server. The next time your disk fills up, you will know about it from an email, not from a failed deploy.
All commands and defaults verified 19 November 2026 against the Docker, MySQL, and Linux documentation linked below.
Further Reading & References
- Find and Free Up Disk Space on a Linux VPS — vpsshell.com
- Fix a Disk Full Linux VPS (2026) — ZoomNod
- VPS Disk Full? Find Large Files & Clean Logs Safely — AsiaGB
- docker system prune — Docker Docs (official)
- Purge MySQL Binary Logs Safely and Free Disk Space — AGDATA
- MySQL Binlogs Ate 90GB of My VPS — kha333n.com
- How to Check Disk Space in Linux: df, du, and ncdu — DarazHost
- Check disk usage & find large files: df, du, ncdu — VMHeaven


