How to Check and Manage Disk Usage on a Linux VPS

Running out of disk space can bring down databases, break log writing, and crash applications. This guide covers finding what's consuming your storage and safely reclaiming space.

Checking Overall Disk Usage

df -h

Focus on the Use% column — anything consistently above 85% needs attention.

Finding Which Directories Are Largest

sudo du -h --max-depth=1 / 2>/dev/null | sort -hr | head -15

Then drill into the largest directory:

sudo du -h --max-depth=1 /var 2>/dev/null | sort -hr

Using ncdu for Interactive Exploration (Recommended)

sudo apt install ncdu -y
sudo ncdu /

ncdu lets you navigate directories interactively and see exactly what's consuming space — much faster than repeated du commands.

Common Culprits

Log Files

sudo du -sh /var/log/*

Check journal size specifically:

sudo journalctl --disk-usage

Trim it:

sudo journalctl --vacuum-time=7d

Package Cache

sudo apt clean
sudo apt autoremove -y

Docker (If Installed)

docker system df
docker system prune -a

Old Kernels

dpkg -l | grep linux-image

Remove old, unused kernel versions with apt autoremove (Ubuntu/Debian handle this automatically in most cases).

Finding Large Individual Files

sudo find / -xdev -type f -size +100M -exec ls -lh {} \; 2>/dev/null

Checking Inode Usage (Different from Disk Space)

Sometimes a disk shows free space but you still get "No space left on device" — this means you've run out of inodes (often caused by millions of tiny files, like session or cache files):

df -i

Extending Disk Space

If you've genuinely outgrown your current storage, resizing the VPS plan (via your provider's control panel, usually followed by a filesystem resize) is the correct long-term fix rather than repeated manual cleanup.

Common Errors

"No space left on device" but df shows free space — check inode usage with df -i; you may have hit the inode limit.

Deleted a large file but space wasn't freed — a process may still hold the file open. Find and restart it:

sudo lsof +L1

Best Practices

  • Set up log rotation and journal size limits proactively, not reactively
  • Monitor disk usage regularly rather than waiting for a failure
  • Automate cleanup (old logs, package cache) via cron

FAQ

Is it safe to delete files in /var/log?
Generally yes, for older rotated logs (e.g. *.log.1, *.gz), but avoid deleting the active log file a running service is currently writing to — rotate or truncate it instead.

Related Articles

  • How to Check VPS Resource Usage (CPU, RAM & Disk)
  • How to Read and Analyze Linux Logs with journalctl
  • How to Choose the Right VPS Plan for Your Workload
  • disk usage, df, du, ncdu, linux storage, server administration
  • 0 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

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...