How to investigate low disk space on Linux
A diagnostic method to find out why the disk is full: df to find the mount, du for the directory, and the confusing cases like inodes and deleted files.
The alert always arrives at the worst moment: "no space left on device". The service stops coming up, the database refuses writes, the deploy breaks halfway through. The instinctive reaction is to SSH in and start deleting whatever looks disposable — an old log, a cache, that forgotten .tar.gz. That is exactly where you go wrong. Running out of disk space is not solved by guessing; it is solved with a method.
This guide is about diagnosis, not a loose list of commands. The goal is to answer the right question — "why is this disk full?" — before touching a single file. The focus is Linux on servers, with special attention to /var/log, Docker, and caches, which is where space actually disappears.
Start with the mount, not the file
The first mistake is jumping straight to du on the root. Before that, you need to know which filesystem is full. A typical server has several independent mounts: /, /var, /home, /boot, maybe a separate volume for Docker. Deleting files in /home does nothing if the one that filled up was /var.
df -h
Read the Use% column and the Mounted on column. The mount at 100% (or close to it) is your target. Note the path — every step of the investigation continues from there. If /boot is full, the culprit is almost always old kernels; if it is /, check whether Docker or logs are sitting on the root for lack of a dedicated volume.
One detail that confuses a lot of people: df -h reports in base 1024 (MiB, GiB), while the cloud provider sells the disk in base 1000 (MB, GB). A "100 GB disk" shows up as ~93 GiB, and that ~7% gap is enough to cause needless panic when someone thinks gigabytes "vanished". When you reconcile the numbers, converting the units between base 1024 and base 1000 avoids that scare.
Drill down with du from the offending mount
With the mount identified, du comes in to pinpoint the responsible directory. The key is not to run du on the entire disk root — that is slow and dumps thousands of lines. Run it with limited depth, starting from the full mount, and sort largest to smallest.
du -h --max-depth=1 /var | sort -rh | head -20
The output puts the largest directory on top. Found the first-level culprit (say, /var/lib/docker)? Repeat one level deeper:
du -h --max-depth=1 /var/lib/docker | sort -rh | head -20
You descend like this, level by level, until you reach the concrete folder that is blowing up. It is a bisection method: each step eliminates half the disk from suspicion. In a few iterations you go from "the disk is full" to "it is the container logs in /var/lib/docker/containers".
If you would rather navigate interactively instead of repeating commands, ncdu is the best tool for the job. It scans once and gives you an arrow-navigable interface with sizes already sorted:
ncdu /var
For the related task of listing the largest individual files (not directories), the method is a bit different and deserves its own treatment — I covered that in how to find large files on Linux. Here the focus stays on diagnosing why it is full.
When du doesn't match df
This is the case that makes good engineers lose an hour. df -h says the disk is at 95%, but du summing everything gives far less. The numbers don't add up. The explanation is almost always the same: a process has a file open that has already been deleted from the filesystem.
On Linux, when you delete a file that is still open by a process, the inode is not freed until the process closes the descriptor. The file disappears from ls and du — but it keeps occupying space, and df still counts it. Classic case: someone runs rm on a 20 GB log that the service is still writing to.
lsof | grep deleted
The output shows which process holds the deleted file and how much it occupies. The fix is not to delete it again (there is nothing left to delete) — it is to restart or signal the process so it releases the descriptor. For many services, a kill -HUP on the PID is enough to reopen the log files; for others, only a restart works. After that, the space comes back in df immediately.
Inodes exhausted with space to spare
The opposite also happens and is equally baffling: df -h shows plenty of free space, yet writes still fail with "no space left on device". The culprit here is not space — it is inodes.
Every file, no matter how tiny, consumes an inode. A filesystem has a fixed number of them, set at format time. If something generates thousands upon thousands of tiny files — PHP sessions, mail caches, queue jobs, temporary files never cleaned up — you can exhaust the inodes long before you exhaust the bytes.
df -i
An IUse% column at 100% confirms the diagnosis. From there it is du again, but now hunting for count of files, not size. To count files per directory, something like for d in /var/*; do echo "$(find "$d" -type f | wc -l) $d"; done | sort -rn points to the directory with millions of files. The fix is to delete the horde of small files and, more importantly, find out what created them to stop the bleeding.
The usual suspects: logs, journald, and Docker
In practice, three sources account for most full disks on servers.
/var/log and journald. Logs without rotation grow indefinitely. systemd's journald, in particular, is often configured with no limit and swallows gigabytes. You can trim the journal without touching files manually:
journalctl --disk-usage
journalctl --vacuum-size=200M
That shrinks the journal to 200 MB and discards the rest. For application logs, check that logrotate is active and configured — an unrotated log is only a matter of time before it shows up here again.
Docker. It is the silent champion. Old images, stopped containers, orphaned volumes, and build cache pile up in /var/lib/docker without anyone noticing. docker system df shows how much each category occupies, and docker system prune -a --volumes clears what is unused — carefully, because --volumes deletes unreferenced data. Container logs also grow without limit unless you set log-opts with max-size on the daemon.
Caches. Package manager caches (apt, yum), build caches (npm, composer, pip), and application caches accumulate. They are safe to clear, but treat that as temporary relief, not a solution.
The difference between deleting and solving
Here is the opinion that matters: clearing the disk is not the same as solving the problem. If you ran vacuum, ran prune, and went to bed, I guarantee the alert comes back — in a week or a month, but it comes back. The disk filled up for a reason, and that reason is still there.
Solving means closing the tap. Configure logrotate for every application log. Set a limit in journald via SystemMaxUse. Put max-size and max-file on Docker logs. Schedule a periodic docker system prune. Monitor the disk with an alert at 80%, not at 100% — you want to find out before the service goes down, not after. Good diagnosis prevents today's fire; good configuration prevents tomorrow's.
Frequently asked questions
Why is the disk full but du shows low usage?
It is almost always a deleted file still open by a process. On Linux, space is only freed when the last file descriptor is closed, so a deleted log that a service is still writing to keeps counting in df but disappears from du. Run lsof | grep deleted to find the process and restart it or send kill -HUP to release the space.
How do I find out what is filling up /var?
Run du -h --max-depth=1 /var | sort -rh | head -20 to see which subdirectory is largest, then descend level by level repeating the command on the top directory. The usual culprits are /var/log (unrotated logs), /var/lib/docker (images and containers), and /var/cache. ncdu /var does the same navigation interactively.
What do I do when df -i shows 100% inodes?
You have exhausted inodes, not space — usually because of thousands of tiny files like sessions, caches, or temporaries. Locate the directory with the most files (not the largest in size) by counting entries per folder, delete the horde of small files, and above all find out what generates them to keep them from coming back. Increasing the inode count requires reformatting the filesystem, so prevention is the way.
Is journalctl --vacuum-size safe to run in production?
Yes. It only discards old journal entries down to the size you set, without affecting running services or losing recent logs. Use journalctl --disk-usage first to see how much is occupied, then configure SystemMaxUse in /etc/systemd/journald.conf to enforce the limit permanently.
What to take from this guide
Have a method and always follow the same order: df -h to find the full mount, du (or ncdu) descending from there to isolate the directory, and only then the action. When the numbers don't match, remember the two classic cases — a deleted file still open (lsof | grep deleted) and exhausted inodes (df -i). And when the disk can breathe again, don't stop there: configure log rotation, limits on journald and Docker, and an alert at 80%. Diagnosis gets you out of the jam; configuration keeps the jam from coming back.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.