29.04.2025
During the operation of Linux servers, a common issue arises — disk space runs out. At IT Lab, we have prepared a professional guide on how to quickly identify which directories consume the most space and how to safely clean them up.
To find out which folders occupy the most space, use the command:
sudo du -h --max-depth=1 / | sort -rh
This command shows the heaviest directories at the server root.
To dive deeper into a specific directory (for example, /var), repeat the command:
sudo du -h --max-depth=1 /var | sort -rh
Typically, the main consumers of space are located in the /var folder, especially in subdirectories:
/var/lib is a system directory that stores:
To analyze it, use:
sudo du -h --max-depth=1 /var/lib | sort -rh
If Docker usage is high:
docker system df
docker system prune -a
⚠️ Important: the prune -a command deletes all unused images and stopped containers. Be cautious.
If databases are consuming space:
OPTIMIZE TABLE table_name;
The /var/log folder stores system and service logs. Over time, they can grow significantly.
Log cleanup:
sudo journalctl --vacuum-size=500M
sudo rm -rf /var/log/*.gz /var/log/*.1 /var/log/*.old
After all operations, check the occupied space:
sudo du -h --max-depth=1 /var | sort -rh
If /var/lib still takes up suspiciously large space, provide the diagnostic output with:
sudo du -h --max-depth=1 /var/lib
This guide was prepared by the IT Lab team — your reliable partner in software and comprehensive server infrastructure support.
Share:
Your reliable IT partner. Only halal solutions, trust, and full technical support for your business growth.
Navigation
Working Hours
© 2026 LABORATORIYAI TEKHNOLOGIYAHOI ITTILOOTI LLC · IT Lab™