How to Fix a Full Disk on a Linux Server (Step-by-Step Guide)
A full disk is one of the most common — and most disruptive — problems a Linux server can run into. When storage runs out, services crash, logs stop writing, databases refuse new connections, and websites can go down entirely. The good news is that a full disk on Linux is almost always fixable in minutes once you know where to look.
This guide walks through practical, safe steps to diagnose and fix disk space issues on any Linux server, whether you're running Ubuntu, Debian, CentOS, or AlmaLinux.
1. Confirm the Disk Is Actually Full
Start by checking overall disk usage with:
df -h
This shows disk space per partition in a human-readable format. If any partition (especially / or /var) is at 90–100% usage, that's your problem.
2. Find Out What's Eating Your Disk Space
Once you know a partition is full, the next step is finding what is consuming the space. The du command is your best friend here:
du -h --max-depth=1 / | sort -rh | head -20
This lists the largest directories at the top level, sorted from biggest to smallest. Run it again inside suspicious folders (like /var/log or /home) to drill down further.
3. Check Log Files First
Log files are the number one cause of a full disk on Linux servers, especially when an application is stuck in an error loop and writing endless log entries.
du -sh /var/log/*
If you find an oversized log file, you can safely truncate it without deleting it (which keeps the file handle intact for running processes):
truncate -s 0 /var/log/large-file.log
For long-term prevention, set up log rotation using logrotate, which most distros already include but may need proper configuration for your specific application.
4. Clean Up Package Manager Cache
Package managers cache downloaded files that pile up over time.
- Debian/Ubuntu:
apt clean
apt autoremove
- RHEL/CentOS/AlmaLinux:
dnf clean all
dnf autoremove
This alone can free up several hundred megabytes to a few gigabytes, depending on how long the server has been running.
5. Remove Old Kernels
Linux systems keep old kernel versions after updates, and they can accumulate significant space over time.
- Ubuntu/Debian:
apt autoremove --purge
- RHEL-based systems:
dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
Always keep at least one working kernel as a fallback.
6. Find and Delete Large or Unused Files
Sometimes the culprit is a single large file — a forgotten backup, a core dump, or a leftover database export.
find / -xdev -type f -size +500M -exec ls -lh {} \;
This searches the entire filesystem for files larger than 500MB so you can review and delete them safely.
7. Check for Deleted Files Still Held Open
This is a tricky one: a file can be deleted but still take up space if a running process still has it open (common with logs and databases).
lsof +L1
If you find such a file, restarting the related service will usually release the space.
8. Clear Docker Resources (If Applicable)
If you're running Docker, unused images, containers, and volumes are a frequent hidden cause of disk bloat:
docker system prune -a --volumes
Use this carefully — it removes all unused Docker data, not just old versions.
9. Set Up Monitoring to Prevent It Happening Again
Fixing a full disk once isn't enough — you want to catch it early next time. Consider:
- Setting up disk usage alerts (e.g., via
cron+ a simple script, or tools like Netdata, Zabbix, or Uptime Kuma) - Enabling
logrotateproperly for all applications - Scheduling regular cleanup jobs for temp files and old backups
A full disk on a Linux server is rarely a sign of a serious hardware issue — in most cases, it's an accumulation of logs, cache, old kernels, or forgotten files. By working through df, du, log cleanup, package cache clearing, and Docker pruning, you can usually recover disk space within minutes. Add basic monitoring afterward, and you'll catch the next warning sign long before your server runs out of space again.

