Disk Usage Analysis on the Server and Efficient Space Cleanup

Blog

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.

Step 1. Identifying where the space is used

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
  • /var/log

Step 2. Working with /var/lib

/var/lib is a system directory that stores:

  • Docker data (/var/lib/docker)
  • Databases (e.g., MySQL /var/lib/mysql, PostgreSQL /var/lib/postgresql)
  • System data of services

To analyze it, use:

sudo du -h --max-depth=1 /var/lib | sort -rh

What to do:

If Docker usage is high:

  1. Check space usage:
docker system df
  1. Remove unused containers, images, and volumes:
docker system prune -a

⚠️ Important: the prune -a command deletes all unused images and stopped containers. Be cautious.

If databases are consuming space:

  • Delete old databases or backups.
  • Optimize tables (for MySQL):
OPTIMIZE TABLE table_name;
  • Archive old data if necessary.

Step 3. Working with /var/log

The /var/log folder stores system and service logs. Over time, they can grow significantly.

Log cleanup:

  1. Limit the size of systemd journals:
sudo journalctl --vacuum-size=500M
  1. Remove compressed and old log files:
sudo rm -rf /var/log/*.gz /var/log/*.1 /var/log/*.old

Step 4. Verification after cleanup

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

Important to remember

  • Backup: Always create backups of important files and databases before deleting any data.
  • Analysis: Do not delete files or directories unless you are sure of their purpose.
  • Monitoring: We recommend setting up automatic disk space monitoring using tools like Prometheus + Grafana or Zabbix.

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

About UsProjectsServicesProductsNews & BlogContacts

Working Hours

Weekdays: Monday to Friday from 09:00 to 21:00Saturday: from 09:00 to 18:00Sunday: closed

Contacts

+992 (088) 11-6666info@itlab.tjAyni Street, 16, Dushanbe

© 2026 LABORATORIYAI TEKHNOLOGIYAHOI ITTILOOTI LLC · IT Lab™