How to Check Disk Space on a VPS Server and Remove Unnecessary Files

First, you need to understand what is taking up space. You can do this using standard utilities available on any Unix-like system.

Run the command:

df -h

This command shows the overall disk usage in a human-readable format. It gives an overview of all mounted file systems:

user@hostname:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.4M  1.6G   1% /run
/dev/sda2       441G   25G  393G   6% /
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/sda1       300M  3.5M  296M   2% /boot/efi
tmpfs           7.8G   32K  7.8G   1% /tmp
tmpfs           1.6G   52K  1.6G   1% /run/user/116
tmpfs           1.6G   56K  1.6G   1% /run/user/1000
user@hostname:~$

Searching and Deleting Unnecessary Files

Once you identify large directories, you can start the “cleanup.” Here’s a list of common candidates for removal:

Log Files

They often grow to huge sizes, especially if your application generates many errors. Logs are usually stored in /var/log. You can use the find command to locate them. For example, to find all log files older than 30 days and delete them:

find /var/log -type f -name "*.log" -mtime +30 -exec rm {} \;

Old Backups

Sometimes backups are created but never deleted. They may be located anywhere, but usually can be identified by file names such as *.tar.gz or *.zip.

Cache

For example, package cache. In Debian/Ubuntu, it’s stored in /var/cache/apt/archives. You can clean it with:

sudo apt-get clean

Build and Temporary Files

If you’ve compiled something, check src, build, and tmp directories for leftover temporary files.

Order a VPS server.