Fix a full disk on a Linux server
A full disk is fixed by finding the biggest directories with df and du, then removing or shrinking what filled it, such as logs, journal files, Docker data or deleted files still held open.
- Updated Nov 27, 2026
- Markdown
Find what filled the disk of a Linux server and free space safely without deleting data you still need.
- SSH access to the server with sudo
Writes start failing, a deploy dies halfway, a database refuses to start, and the error says No space left on device. The disk is full, and you need to find out what filled it before you delete anything. The fast path is df to find the full filesystem, du to find the directory, and a short list of usual suspects: logs, the journal, Docker data, files held open after deletion, and inodes.
How it works#
A filesystem has two limits: bytes and inodes. Bytes are the data, and an inode is one record per file or directory. Either can run out. When the root filesystem is full, almost everything on the server breaks at once, because services need to write logs, sockets, temporary files and databases.
Linux frees a file’s space only when two things are true: no directory entry points at it, and no process has it open. That is why deleting a large log from under a running process often frees nothing. Keep that in mind during Step 4.
Step 1: Find the full filesystem#
df -hRead the Use% column and the Mounted on column. A server can have several filesystems, and only one may be full. Ignore tmpfs entries unless one is full, since they live in memory. Note the mount point of the full one, for example /, and use it as the starting point below. See check disk, memory and CPU usage for more on reading this output.
Step 2: Find the directory that holds the space#
sudo du -xh --max-depth=1 / 2>/dev/null | sort -hThe -x flag keeps du on one filesystem, so it does not wander into other mounts and give you misleading totals. Sort puts the biggest entry last. Take the biggest directory and repeat the command on it, for example sudo du -xh --max-depth=1 /var | sort -h. Two or three rounds usually lands on the culprit. Do not run du on /proc or other virtual filesystems, and expect it to be slow on very large trees.
Step 3: Check the usual suspects#
Logs. Look in /var/log. A single application log that grows without rotation is the classic cause. Check whether logrotate covers it, and for containers see limit Docker log size.
The systemd journal.
journalctl --disk-usage
sudo journalctl --vacuum-size=500MThe vacuum command deletes the oldest archived journal files until the total is under the size. Pick a size that still keeps the history you need. Old log entries are gone for good afterwards.
Docker.
docker system dfThis table shows images, containers, volumes and build cache, with a RECLAIMABLE column. Do not rush to prune. Volumes can hold your database. Follow free disk space with docker prune safely, which separates the safe commands from the dangerous ones. Container JSON logs live under /var/lib/docker/containers/ and are not shown as a separate row.
Package caches and old kernels. On Ubuntu, sudo apt clean clears downloaded packages, and sudo apt autoremove lists old unused packages and asks before removing them.
Step 4: Look for deleted files that are still open#
If df says the disk is nearly full but du finds far less, a process is holding a deleted file:
sudo lsof +L1+L1 lists open files with a link count below one, meaning deleted. The SIZE/OFF column shows how big each one is and COMMAND and PID show who holds it. The space comes back when that process closes the file, which for most services means restarting it (sudo systemctl restart nginx, or docker restart <container>). Restart only what you understand, and do it in a quiet moment if the service is serving users. Never delete a log file that is in use as a fix: truncate it from the application’s own rotation instead.
Step 5: Check inodes#
If writes fail but df -h shows free bytes, check inodes:
df -iWhen IUse% is at 100 percent, you have too many small files. To find the directory with the most files, count entries per top directory:
sudo find /var -xdev -type f | cut -d/ -f1-4 | sort | uniq -c | sort -n | tailCommon sources are session files, mail queues, cache directories and build artifacts. Remove the old files only after you know what owns them.
Step 6: Free the space#
Now act on what you found. Delete or compress old backups you have already copied elsewhere, vacuum the journal, prune Docker data you checked, and remove old release directories. For a log that must keep its file but lose content, truncate is safe for a running process:
sudo truncate -s 0 /var/log/myapp/app.logThis empties the file and cannot be undone, so use it only on logs you do not need. Then fix the cause, not just the symptom: add log rotation, set Docker log limits, or grow the disk.
Check it worked#
df -h /
df -i /Use% should have dropped well below 100, and the service that failed should start again. Watch it for a day: if usage climbs back fast, something is still writing. sudo du -xh --max-depth=1 /var | sort -h on the same directory shows whether it regrew.
Prevent it#
- Rotate logs and cap Docker logs with
max-sizeandmax-file. - Add a disk usage alert at around 80 percent, using uptime monitoring or your provider’s tools.
- Keep backups on another machine, not in
/var/backupson the same disk.
Edge cases and gotchas#
- Reserved blocks: ext4 reserves a slice for root, so
Availcan reach zero for normal users while root can still write. - Mounts hiding data: Files written to a directory before a disk was mounted over it still use space on the lower filesystem, and
ducannot see them until you unmount. - Sparse and large database files: A file’s apparent size and real size can differ.
du -hshows disk use,ls -lhshows apparent size. - Snap and container layers: Old snap revisions and overlay layers are kept on purpose. Remove them with the tool that owns them, not with
rm. - Deleting while a deploy runs: Free space before retrying a failed deploy, since a half-written image layer may remain.
- Backups in the same tree: A backup job that writes to the disk it is backing up can fill it when it fails to clean up.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| df 100 percent, du much smaller | Deleted file still held open | sudo lsof +L1, restart the holding process |
| No space left but df -h shows free | Inodes exhausted | df -i, remove piles of small files |
/var/lib/docker is huge | Images, build cache or volumes | docker system df, then prune with care |
| Journal uses gigabytes | No size limit set | journalctl --vacuum-size, set SystemMaxUse |
| Space returns then vanishes | A process keeps writing | Find it with du over time, fix the logging |
| du is very slow | Scanning network or virtual mounts | Use -x and start from the right directory |
Quick reference#
df -h
df -i
sudo du -xh --max-depth=1 / | sort -h
journalctl --disk-usage
sudo journalctl --vacuum-size=500M
docker system df
sudo lsof +L1Related lessons#
- Check disk, memory and CPU usage: read df, free and top without guessing.
- Free disk space with docker prune safely: which prune commands are safe and which delete volumes.
- Limit Docker log size: stop container logs from filling the disk again.
- Read logs with journalctl: understand the journal you are vacuuming.
- Backups and the 3-2-1 rule: keep copies off the disk that can fill.
Next#
Continue with Fix 504 Gateway Timeout behind a reverse proxy.
Try it: Find what filled the disk
Walk from the full filesystem down to the directory that owns the space, then check Docker and the journal.
Want a real machine? Free browser labs: Killercoda
Check what you learned
Frequently asked questions
Why is my Linux server disk full?
The usual causes are growing log files, a large systemd journal, Docker images and build cache, old backups, or a deleted file that a running process still holds open. df shows which filesystem is full and du shows where the space went.
Why does df say the disk is full but du shows less?
A process probably still holds a deleted file open, so the space is not released until the process closes it. Run sudo lsof +L1 to list those files, then restart the process.
How do I free disk space on Ubuntu quickly?
Find the largest directories with du, vacuum the journal with journalctl --vacuum-size, and clean unused Docker data with the docker prune commands. Check what each command removes before running it.
What does No space left on device mean when df shows free space?
The filesystem may have run out of inodes, not bytes. Run df -i to check the IUse% column.
Sources
Keep going: guides and tutorials
- Docker Container Restarting in a Loop: 5 Causes, Fixed Five real reasons a Docker container keeps restarting, each reproduced with its exit code, the command that finds it and the fix. Then the same crash on Levelrail.
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.
- Roll Back a Failed Docker Deploy Without Downtime Ship a broken release on purpose, watch your users stay on the old version, then roll back with one command. Real commands, real output, self-hosted.