How to check and free up disk space on Linux VPS
Full disk can prevent updates, databases, logs and applications from working. Before deleting any file, identify the responsible directory and keep a backup of important data.
1. Check the use of partitions
df -h
Note the Use% column. The -h option shows readable sizes.
To check inodes:
df -i
A partition can fail due to lack of inodes even when it still has space in bytes.
2. Discover the biggest directories
At the root of the system:
sudo du -xhd1 / 2>/dev/null | sort -h
Then repeat in the larger directory. Example:
sudo du -xhd1 /var 2>/dev/null | sort -h
The -x option avoids traversing other file systems.
3. Find large files
sudo find / -xdev -type f -size +500M -printf "%s %p\n" 2>/dev/null | sort -n
Review the purpose of each file. Don't remove database, swap, or system files just for size.
4. Clear APT cache
See the size:
sudo du -sh /var/cache/apt
Clean downloaded packages:
sudo apt clean
Review unused dependencies:
sudo apt autoremove
Please read the list before confirming the removal.
5. Check systemd logs
journalctl --disk-usage
To keep just the last seven days:
sudo journalctl --vacuum-time=7d
This deletes old logs. Preserve records needed for auditing or diagnostics before running.
6. Check traditional logs
sudo du -h /var/log | sort -h | tail -n 20
Applications must use log rotation. Avoid simply deleting a file that remains open by a process.
Check the Logrotate configuration:
sudo logrotate -d /etc/logrotate.conf
The -d option simulates without changing files.
7. Check Docker
If you use Docker:
docker system df
List containers, images, and volumes before any cleanup:
docker ps -a
docker images
docker volume ls
Prune commands can remove stopped resources that are still needed. Do not run automatic cleaning without reviewing.
8. Confirm the result
df -h
Monitor again after a few hours or days to find out if growth continues.
Frequently asked questions
Can I delete everything from /var/log?
No. Logs are important and some services depend on the file structure. Configure retention and rotation.
What takes up space even after deleting a file?
A process can keep the file open. Check:
sudo lsof +L1
Restart only the responsible service after evaluating the impact.
How to avoid a full disk?
Configure alerts, log rotation, backup retention and periodic review.
If you need help, open a ticket with Nice Hosting support.