Hostxpeed
Login Get Started →
Server Management

How to Clean Up Disk Space

7 min read
24 views
Jun 12, 2026

Prerequisites

Before cleaning disk space, make sure you have:

  • SSH access to your VPS
  • Root or sudo privileges

⚠️ Always check what you are deleting. Some commands are irreversible!

Step 1: Check Current Disk Usage

Connect to your VPS:

ssh hxroot@YOUR_SERVER_IP -p 22
df -h
du -sh /var /home /root /tmp

Step 2: Find Largest Files and Directories

du -ah / | sort -rh | head -20
find / -type f -size +100M -exec ls -lh {} ; 2>/dev/null

Step 3: Clean Package Cache (Ubuntu/Debian)

sudo apt clean
sudo apt autoremove -y
sudo apt autoclean

Step 4: Remove Old Logs

Rotate and compress logs:

sudo logrotate -f /etc/logrotate.conf

Delete logs older than 30 days:

sudo find /var/log -type f -name "*.log" -mtime +30 -delete

Clear journal logs (systemd):

sudo journalctl --vacuum-time=7d

Step 5: Clean Temporary Files

sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*

Step 6: Remove Old Kernels (Ubuntu/Debian)

dpkg --list | grep linux-image
sudo apt autoremove --purge

Step 7: Clean Docker (If Installed)

docker system prune -a -f

Step 8: Clean User Cache

rm -rf ~/.cache/*

Step 9: Remove Orphaned Packages

sudo deborphan | xargs sudo apt-get remove -y

Step 10: Empty Trash (If Any)

rm -rf ~/.local/share/Trash/*

Automated Cleanup Script

#!/bin/bash
echo "Starting disk cleanup..."
apt clean
apt autoremove -y
journalctl --vacuum-time=7d
find /var/log -type f -name "*.log" -mtime +30 -delete
echo "Cleanup completed. Disk usage:"
df -h /

Add to cron for weekly run:

0 2 * * 0 /root/cleanup.sh

✅ Disk space has been cleaned up. Monitor regularly to prevent full disks.

Was this article helpful?