In short
When a Linux server's disk is full, use df -h to find the full partition, then du -xh --max-depth=1 / | sort -h or ncdu -x / to find the directory using the space. The most common causes are growing logs, the systemd journal, Docker images and the apt cache. Clean them with truncate, journalctl --vacuum-size, docker system prune and apt clean, then prevent a repeat with logrotate and a journald limit.
In this guide
- Emergency: Disk at 100% and Services Are Down
- 1. Which Partition Is Full? Diagnose with df
- 2. What Is Using the Space? Search with du and ncdu
- 3. Safe Cleanup: The Most Common Space Hogs
- 4. Preventing a Repeat: logrotate and a journald Limit
- What Not to Do When the Disk Is Full
- If Cleanup Isn't Enough: Is the Disk Simply Too Small?
- Next Steps
When the disk on a Linux server fills up, first use df -h to see which partition is full, then du -xh --max-depth=1 / | sort -h or ncdu -x / to find which directory is using the space. The usual culprits are growing log files, the systemd journal, old Docker images and the apt cache. After a safe cleanup, logrotate and journald limits keep the problem from coming back.
The symptoms of a full disk are usually indirect: the database crashes, the site returns 500 errors, you can SSH in but can't save files, or you see No space left on device in the logs. This guide helps you reclaim space without panicking and without deleting the wrong file.
Emergency: Disk at 100% and Services Are Down
If your site is down right now, free up some space quickly and get services running again first; do the permanent fix afterward. On most servers, the three commands below free anywhere from a few hundred MB to a few GB within minutes and don't touch any user data:
sudo apt clean
sudo journalctl --vacuum-size=100M
docker system prune -f 2>/dev/null
Then restart the crashed service (for example, sudo systemctl restart mariadb) and check the status with df -h. Once you have some breathing room, use the steps below to find the root cause; otherwise the disk will fill up again within hours or days.
1. Which Partition Is Full? Diagnose with df
df -h
In the output, look for the row whose Use% column is close to 100%. Most VDSs have a single root partition (/); some setups have /var or /home on separate partitions. tmpfs rows live in memory and have nothing to do with a disk problem.
Space available but still getting "disk full" errors?
In two cases, writes fail even though df -h shows free space:
- Inode exhaustion: Every file uses one inode. Millions of small files (session files, cache, mail queue) can use up all the inodes. Check with
df -i. IfIUse%is 100%, this is the problem. - Deleted but still open files: If you delete a log file with
rmwhile a process holds it open, the file disappears from the directory, but the space isn't freed until the process closes the file.
# Files that were deleted but are still held open
sudo lsof +L1
# Find directories that consume inodes
sudo du --inodes -x --max-depth=2 / 2>/dev/null | sort -n | tail -15
If you see a large file in the lsof +L1 output, restarting the related service (sudo systemctl restart servis-adi, using your service's name) gives the space back immediately.
2. What Is Using the Space? Search with du and ncdu
Drilling down directory by directory with du
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -15
The -x option keeps du from crossing into other file systems (such as /proc or mounted network drives). Once you find the largest directory, repeat the command for that directory: sudo du -xh --max-depth=1 /var | sort -h. More often than not, the trail leads to /var/log, /var/lib/docker or an application's storage folder.
ncdu: interactive and faster
sudo apt install ncdu -y
sudo ncdu -x /
ncdu shows directories sorted by size; you navigate with the arrow keys, press Enter to open a directory and d to delete the selected item. Make sure you know what something is before you delete it.
Listing files above a certain size
sudo find / -xdev -type f -size +500M -exec ls -lh {} \; 2>/dev/null | sort -k5 -h
3. Safe Cleanup: The Most Common Space Hogs
| Source | Check command | Cleanup command |
|---|---|---|
| systemd journal | journalctl --disk-usage | sudo journalctl --vacuum-size=200M |
| apt cache | du -sh /var/cache/apt | sudo apt clean |
| Old kernels and packages | apt list --installed | grep linux-image | sudo apt autoremove --purge |
| Docker | docker system df | docker system prune |
| Application logs | du -sh /var/log/* | truncate + logrotate |
| Old Snap revisions | snap list --all | sudo snap set system refresh.retain=2 |
Log files
Don't delete an active, growing log file; empty it instead. rm leads to the "deleted but still open file" problem described above:
# Resets the file's contents without deleting it
sudo truncate -s 0 /var/log/nginx/access.log
# Removes old, compressed log archives
sudo find /var/log -type f -name "*.gz" -mtime +30 -delete
Laravel storage/logs, WordPress debug.log and application error logs are also frequent offenders. If a log is growing fast, look at its last lines before cleaning it; a constantly repeating error points to the real problem, and if it isn't fixed, the disk will fill up again.
systemd journal
journalctl --disk-usage
sudo journalctl --vacuum-size=200M
# or by age
sudo journalctl --vacuum-time=14d
Docker images, containers and build cache
On servers running Docker, /var/lib/docker can easily reach tens of GB. First see what is taking up space:
docker system df
# Stopped containers, unused networks, dangling images and build cache
docker system prune
# ALL images not used by any container
docker image prune -a
# Build cache only
docker builder prune
Warning: docker system prune --volumes also deletes unused volumes, so the data of a stopped database container can be lost. Inspect volumes one by one and delete them deliberately. To keep container logs from growing without limit, follow our guide on installing Docker on Ubuntu and set the log limit in daemon.json.
Package cache and old kernels
sudo apt clean
sudo apt autoremove --purge -y
4. Preventing a Repeat: logrotate and a journald Limit
Configuring logrotate
logrotate is the Linux tool that rotates log files at set intervals, compresses them and deletes old copies. It comes preconfigured for system services; for your own application you need to create a file under /etc/logrotate.d/. Example: /etc/logrotate.d/uygulama
/var/www/uygulama/storage/logs/*.log {
daily
rotate 14
maxsize 100M
compress
delaycompress
missingok
notifempty
copytruncate
su www-data www-data
}
daily+rotate 14: Rotates daily and keeps 14 copies.maxsize 100M: Also rotates a file that exceeds 100 MB before the day is over (checked whenever logrotate runs).copytruncate: Works safely even if the application keeps the file open.su: Required if the files aren't owned by root.
Test the configuration with a dry run first, then force a single run:
sudo logrotate -d /etc/logrotate.d/uygulama
sudo logrotate -f /etc/logrotate.d/uygulama
A permanent limit for journald
Uncomment and edit this line in /etc/systemd/journald.conf:
[Journal]
SystemMaxUse=500M
sudo systemctl restart systemd-journald
Disk usage alert
A simple cron script is enough to make sure you notice the problem before your users do. /usr/local/bin/disk-uyari.sh:
#!/bin/bash
ESIK=85
KULLANIM=$(df / --output=pcent | tail -1 | tr -dc '0-9')
if [ "$KULLANIM" -ge "$ESIK" ]; then
logger -t disk-uyari "Kok bolum %$KULLANIM dolu"
fi
sudo chmod +x /usr/local/bin/disk-uyari.sh
echo "*/30 * * * * root /usr/local/bin/disk-uyari.sh" | sudo tee /etc/cron.d/disk-uyari
The script logs a message when root partition usage reaches the threshold (ESIK, 85%). You can replace the logger line with your own notification method (email, a Telegram bot or a webhook).
What Not to Do When the Disk Is Full
- Don't manually delete the
ibdata,ib_logfileor binlog files in/var/lib/mysql. Clean up binlogs through the database withPURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;. - Don't delete folders under
/var/lib/dockerwithrm -rf; use Docker's own prune commands. - Don't delete active log files with
rm; usetruncate. - Don't let backups pile up on the server's own disk. They eat space, and if the disk fails you lose the backups along with everything else; send backups to the cloud automatically with rclone.
If Cleanup Isn't Enough: Is the Disk Simply Too Small?
If usage quickly climbs above 80% again even after cleanup, the problem isn't junk but your real, growing data: the database, user uploads or Docker volumes. In that case you need to grow the disk or move static files to external storage. If you are also seeing slowdowns along with the full disk, check whether the disk is the only bottleneck with our guide on diagnosing a slow server: CPU, RAM and disk bottlenecks.
At Sunucu Atlas, VDS plans use NVMe storage, and disk space increases in tiers by plan. For file-heavy projects that need more RAM and disk at a lower cost, the Intel Premium VDS series offers NVMe options starting at 30 GB. For PHP and database workloads that need high single-core performance, the Ryzen Premium VDS series with the AMD Ryzen 9 5900X has tiers up to 200 GB NVMe.
Next Steps
Once you've reclaimed the space, do three things today: create a logrotate file for your own application log, set the journald limit and install the disk alert cron job. If your current disk can't keep up with how fast your data grows, consider moving to an Intel Premium VDS plan or a Ryzen Premium VDS plan with more NVMe space; if you're unsure which plan to choose, you can open a support ticket.
Frequently asked questions
df shows free space but I get a No space left on device error. Why?
Most likely you've run out of inodes, or there is a deleted file that a process is still holding open. Check inode usage with df -i and deleted-but-open files with sudo lsof +L1.
Is it safe to delete a large log file with rm?
Deleting a log file that is actively being written with rm may not free the space right away, because the service keeps the file open. Instead, reset its contents with truncate -s 0 followed by the file name.
Does docker system prune delete my data?
By default it removes stopped containers, unused networks, dangling images and the build cache, and it doesn't touch volumes. If you add the --volumes option, unused volumes are deleted too and you can lose data.
How much space does the systemd journal take, and how do I limit it?
Run journalctl --disk-usage to see its current size. Set a value such as SystemMaxUse=500M in /etc/systemd/journald.conf and restart the systemd-journald service to apply a permanent limit.
What does logrotate do?
logrotate rotates log files at set intervals, compresses them and deletes old copies. For your own application, you need to add a configuration file under /etc/logrotate.d/.
What should I do if the disk fills up again after cleanup?
If what's growing is real data, you need to enlarge the disk, move backups to external storage or switch to a plan with a larger disk.