When a Linux disk is full, start with df -h to find the full filesystem, then du or ncdu to find the directories using space, and df -i to check whether you ran out of inodes instead of bytes. The usual culprits are logs, the systemd journal, Docker images and volumes, package caches and files that were deleted but are still held open by a process. Free space carefully: some cleanup commands delete data permanently.
Step 1: find the full filesystem
df -h
Look at the Use% column and the Mounted on column. A full / is the classic case, but /var, /boot or a separate data volume can fill up too. Note the mount point: the following commands should stay on that filesystem.
If df -h shows free space but programs still fail with “No space left on device”, check inodes:
df -i
Each file uses one inode. Millions of tiny files (session files, cache entries, mail queues) can exhaust inodes while bytes are still available. To find directories with many files:
sudo find /var -xdev -type f | cut -d/ -f2-3 | sort | uniq -c | sort -n | tail
Step 2: find what is using space
With du
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -20
The -x option keeps du on one filesystem, so it does not descend into other mounts or /proc. Repeat on the largest directory, for example /var, then /var/log, until you find the cause.
To list the largest single files:
sudo find / -xdev -type f -size +500M -exec ls -lh {} \; 2>/dev/null
With ncdu
ncdu is an interactive version of du, available in most distribution repositories:
sudo apt install ncdu # Debian, Ubuntu
sudo dnf install ncdu # Fedora, RHEL-like (may need EPEL)
sudo ncdu -x /
Navigate with the arrow keys and see sizes sorted. Be careful with the d key: it deletes the selected item.
Step 3: common causes and how to clean them
The systemd journal
Check how much space the journal uses:
journalctl --disk-usage
Reduce it by size or by age:
sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=14d
To make the limit permanent, set SystemMaxUse= in /etc/systemd/journald.conf (or a drop-in in /etc/systemd/journald.conf.d/) and restart the service with sudo systemctl restart systemd-journald. Think about how long you need logs for incident investigation before shortening retention.
Log files and logrotate
Large files in /var/log usually mean logrotate is missing a rule, or an application logs too much. Test the configuration without changing anything:
sudo logrotate -d /etc/logrotate.conf
To force a rotation:
sudo logrotate -f /etc/logrotate.conf
Check /etc/logrotate.d/ for a rule covering the growing file, with rotate, maxsize or size, and compress. If an application writes its own log outside /var/log, add a rule for it. Do not rm a log file that a process is still writing to; see the section on deleted-but-open files below. If you need space immediately, truncating is safer:
sudo truncate -s 0 /var/log/myapp/huge.log
Package caches
sudo apt clean # Debian, Ubuntu
sudo dnf clean all # Fedora, RHEL-like
On /boot, old kernels are the usual problem. On Debian and Ubuntu, sudo apt autoremove removes kernels no longer needed. Review the list before confirming.
Docker
Docker can use a lot of space in /var/lib/docker. See the breakdown first:
docker system df
docker system df -v
Then clean up selectively, from safest to most destructive:
docker image prune # dangling images only
docker builder prune # build cache
docker container prune # stopped containers
docker image prune -a # all images not used by a container
docker system prune combines several of these: it removes stopped containers, unused networks, dangling images and build cache. Read the confirmation prompt.
Warnings:
docker system prune -aremoves every image not used by a running or stopped container. Images will be pulled again, which may fail if a registry is unavailable or a tag has changed.docker volume pruneanddocker system prune --volumesdelete volumes, which often hold databases. This is permanent data loss if you have no backup. Checkdocker volume lsand know what each volume contains before running it.- A stopped container may be one you still need. Check
docker ps -abefore pruning containers.
Container logs can also grow without limit with the default json-file driver. Set max-size and max-file in /etc/docker/daemon.json, as described in the Docker logging documentation. The change applies to newly created containers.
Step 4: deleted-but-open files
Sometimes du finds much less than df reports as used. The difference is often files that were deleted while a process still has them open. The space is not released until the process closes the file.
Find them:
sudo lsof +L1
This lists open files with a link count below 1, meaning deleted. Look at the SIZE/OFF column and the process name. The cleanest fix is to restart the service that holds the file:
sudo systemctl restart nginx
If a restart is not possible right now, you can truncate the file through /proc, using the PID and file descriptor number shown by lsof:
sudo truncate -s 0 /proc/<PID>/fd/<FD>
Only do this for log files or similar data you do not need. This is also why you should truncate active logs rather than delete them.
Step 5: reserved blocks on ext4
On ext4 filesystems, a percentage of blocks (often 5% by default) is reserved for root. This is why a disk can be “full” for normal users while root can still write. You can check it with sudo tune2fs -l /dev/sdXN | grep -i reserved. Reducing the reservation frees space, but the reserve exists to keep the system usable when the disk fills up, so do not set it to zero on the root filesystem.
Step 6: forecast instead of firefighting
A disk rarely fills up instantly. Usually it grows steadily, and the outage happens on a weekend. Prevent it:
- Monitor usage over time, not just the current value. A disk at 70% growing 2% per day is more urgent than one stable at 85%.
- Estimate time to full: divide free space by the average daily growth.
- Set alerts with margin, for example at 80% and 90%, and on inode usage as well.
- Fix the cause: add logrotate rules, limit journal and Docker log size, schedule cache cleanup.
- Resize if growth is legitimate: databases and uploads grow by design. Plan capacity.
How Avanguard helps
- The agent reports disk usage and inodes every 15 seconds and disk usage by directory in its hourly full scan, so you can see where space goes without logging in.
- It provides a disk-full forecast, alerts on thresholds you choose and flags oversized logs. See Linux server monitoring.
- The “free up space” feature uses fixed cleanup recipes with a preview first; you choose what to run, and it runs through the terminal key. The AI never writes deletion commands.
Summary
df -hto find the full filesystem;df -ito check inodes.du -xh --max-depth=1orncdu -xto find the directories using space.- Clean the journal with
journalctl --vacuum-sizeand setSystemMaxUse. - Fix logrotate rules; truncate active logs instead of deleting them.
- Clean package caches and old kernels.
- Use
docker system dffirst; prune carefully and never prune volumes without a backup. - Run
lsof +L1whenduanddfdisagree. - Monitor growth and forecast, so the next full disk is a ticket, not an outage.