How to Clean Up Disk Space on a Linux VPS (Safe Practices)

A VPS running low on disk space can cause application failures, database corruption, or a complete outage. This guide covers safely identifying and reclaiming disk space without accidentally breaking something important.

Step 1 — Get an Overview of Disk Usage

df -h

Step 2 — Find What's Actually Using Space

sudo du -sh /* 2>/dev/null | sort -rh | head -20

Shows the largest top-level directories, sorted by size — drill into the largest ones progressively to find specific space-consuming culprits.

Step 3 — Check for Oversized Log Files

sudo find / -name "*.log" -size +100M 2>/dev/null -exec ls -lh {} \;

Runaway log files are one of the most common causes of unexpected disk usage — see How to Set Up Log Rotation with logrotate to prevent recurrence after cleaning up.

Step 4 — Clean Up Package Manager Cache

sudo apt clean
sudo apt autoremove

Step 5 — Clean Up Old Kernel Versions

sudo apt autoremove --purge

Removes old kernel versions no longer in use, which can accumulate meaningful disk usage on a system with many past updates.

Step 6 — Check for Large Docker Artifacts

docker system df
docker system prune -a

Caution: -a removes all unused images, not just dangling ones — verify you don't need any currently-stopped-but-intended-to-keep images before running this.

Step 7 — Check for Old Backup Files Left Locally

find / -name "*.bak" -o -name "*.old" 2>/dev/null

Review before deleting — some may be intentional and needed; others may be forgotten leftovers from past manual work.

Step 8 — Check for Core Dumps

find / -name "core.*" -size +10M 2>/dev/null

Core dumps from crashed applications can be surprisingly large and are usually safe to delete once any relevant debugging has been completed.

Step 9 — Check systemd Journal Size

journalctl --disk-usage
sudo journalctl --vacuum-size=500M

Caps the systemd journal to a specific size, removing older entries beyond that limit.

What NOT to Do

  • Never delete files in /proc or /sys — these are virtual filesystems, not actual disk-consuming data
  • Don't blindly delete files just because they're large without understanding what they are
  • Don't run broad, unreviewed rm -rf commands based on generic disk-cleanup advice without verifying paths are correct for your specific situation

Preventing Future Disk Space Issues

  • Set up disk usage monitoring/alerting (see How to Set Up Effective Server Alerting)
  • Configure log rotation for all application logs, not just system defaults
  • Periodically review and clean up old backups per your retention policy (see Data Retention Policies: What to Keep and What to Delete)

Common Errors

Deleted files but df still shows full disk — a process may still hold an open file handle to a deleted file, keeping the space allocated until that process restarts; identify with lsof | grep deleted and restart the relevant service.

Continue Reading

Browse more articles in Linux Server Administration.

  • clean disk space linux, free up disk space vps, disk full troubleshooting, linux disk cleanup
  • 0 Korisnici koji smatraju članak korisnim
Je li Vam ovaj odgovor pomogao?

Vezani članci

How to Update and Upgrade Your Ubuntu or Debian VPS

Keeping your VPS updated is one of the most important and simplest maintenance tasks — it...

How to Enable and Configure Swap on a Linux VPS (Ubuntu & Debian)

Swap is disk space Linux can use as overflow memory when physical RAM is exhausted. It won't make...

How to Manage Services with systemd and systemctl

systemd is the service manager used by Ubuntu, Debian, and most modern Linux distributions to...

How to Read and Analyze Linux Logs with journalctl

On modern Ubuntu and Debian systems, journalctl is the central tool for viewing system and...

How to Schedule Tasks with Cron on a Linux VPS

Cron is the standard Linux job scheduler, used to automate recurring tasks like backups, log...