- How to Check if You're Running Out of Disk Space on VPS
- Watching Out for Backup Turnover
- Being Aware of Junk Files
- How Do I Locate the Folders Containing a Particular Set of Data?
- How do I Prevent Disk Space Overages?
- What are the Dangers of Being Too Close to Disk Quota?
- So, What Do I Do if I'm Running Out of Space?
- Final Thoughts
Running out of disk space on your Virtual Private Server (VPS) or dedicated server is a common yet critical issue that can disrupt your operations. Think of disk space as the lifeblood of your server. Without enough room to breathe, everything slows down or stops working entirely. Whether you’re hosting websites, running apps, or managing backups, keeping tabs on your disk usage is non-negotiable if you want reliability and performance.
In this guide, I’ll walk you through practical, hands-on strategies to diagnose and fix disk space issues before they turn into disasters. We’ll cover everything from pinpointing what’s hogging your storage to setting up tools that alert you when things start getting tight. By the time you finish reading, you’ll have a clear plan to keep your server lean, mean, and ready for action. Let’s get into it!
How to Check if You're Running Out of Disk Space on VPS
If you’re managing a VPS, knowing how to check your disk space is a must. The good news? Linux gives you simple yet powerful tools to do just that. Start with the df -h command — this shows you an overview of all mounted filesystems and their usage in a human-readable format (that’s what the -h stands for). You’ll see columns like total size, used space, available space, and the mount point. Keep an eye on the “Use%” column — if it’s creeping close to 100%, it’s time to take action.
Need more detail? Use du -sh /* to break down disk usage by directory. The -s gives you a summary, and -h keeps it readable. This helps pinpoint which folders are hogging space. For example, if /var/log is eating up gigabytes, you might have runaway log files.
Regularly running these commands isn’t just smart — it’s essential. Disk space issues don’t announce themselves; they sneak up on you. Make it a habit to check periodically, or better yet, set up automated monitoring so you’re never caught off guard. Proactive beats reactive every time.
Let’s dive into the practical side of things with real-world examples. If you’re using a Linux-based VPS, two commands are your best friends when it comes to checking disk space: df -h and du -sh. Here’s how they work and how to interpret their output.
Using df -h
Run this command in your terminal:
df -h |
You’ll get an output like this:
Filesystem Size Used Avail Use% Mounted on/dev/vda1 50G 40G 7.5G 85% /tmpfs 16G 0 16G 0% /dev/shm |
Here’s what it means:
- /dev/vda1 is your main disk, and it’s 85% full. That’s getting tight—anything over 80% is a red flag.
- tmpfs is temporary memory storage, and it’s empty, so no worries there.
If you see a partition at 90% or higher, it’s time to investigate further.
Using du -sh
Now, let’s say you’ve identified that your root directory ( / ) is filling up. To find out what’s eating space, use:
du -sh /* |
The output might look like this:
2.5G /home12G /var500M /etc3.0G /usr |
This tells you that /var is the biggest culprit. Maybe it’s log files or cached data piling up. Drill down further with:
du -sh /var/* |
You might discover something like this:
10G /var/log1.5G /var/cache |
Aha! Your /var/log folder is taking up 10GB. Time to clean up old logs.
For those looking to implement best practices for managing disk space on a reliable and high-performing infrastructure, consider a VPS Server Netherlands or VPS Europe — an excellent option for developers and system administrators who value stability, performance, and cost-effectiveness. |
Watching Out for Backup Turnover
Backups are a lifesaver, but they can also be a silent disk-space killer if not managed properly. Over time, accumulated backups — especially full system snapshots — can eat up gigabytes of storage. For example, if you’re running daily backups without a cleanup policy, your /backup directory might balloon to unsustainable levels.
To avoid this, set up automatic deletion of old backups. Tools like logrotate (yes, it works for more than just logs!) or custom scripts can help you retain only the most recent copies. For instance, you could configure a retention policy to keep the last 7 days of backups and delete anything older. Many backup tools, like rsync or cloud-based solutions, also have built-in options for managing turnover.
Regularly audit your backup strategy — not just for reliability, but to ensure it’s not hogging unnecessary space. After all, backups are only useful if they don’t cripple your server in the process.
Using logrotate for Log Backups
Logs can pile up quickly, especially if your server handles a lot of traffic. To manage this, use logrotate, a tool designed to rotate and compress old logs. Here’s an example configuration file for /etc/logrotate.d/nginx:
/var/log/nginx/*.log { daily missingok rotate 7 compress delaycompress notifempty create 0640 root root} |
What this does:
- Rotates logs daily.
- Keeps 7 days’ worth of logs ( rotate 7 ) and deletes older ones.
- Compresses old logs to save space ( compress ).
Run logrotate /etc/logrotate.conf manually or let it run automatically via cron. This ensures old logs don’t fill up your disk.
Automating Backup Cleanup with find
If you’re managing custom backups, you can use the find command to delete files older than a certain age. For instance, to remove backup files in /backup older than 7 days:
find /backup -type f -mtime +7 -exec rm -f {} \; |
This command searches for files ( -type f ) modified more than 7 days ago ( -mtime +7 ) and deletes them ( rm -f ).
Setting Retention Policies in Backup Tools
Many backup tools have built-in retention policies. For example, if you’re using rsync for incremental backups, you can add a cleanup step to your script:
#!/bin/bashrsync -av –delete /source/ /backup/find /backup -type f -mtime +14 -exec rm -f {} \; |
This script syncs data to /backup and removes files older than 14 days.
Being Aware of Junk Files
Temporary files, cache, and leftover data can silently pile up and eat away at your disk space. For example, apps like package managers (/var/cache/apt for Debian/Ubuntu) or web servers often leave behind files that aren’t always cleaned up automatically. If you’re not careful, these junk files can grow into gigabytes of wasted space.
Let’s dive into practical examples of how to identify and clean up junk files like temporary files, cache, and other unnecessary data. These commands will help you reclaim disk space while keeping your system safe.
Cleaning Up /tmp with find
The /tmp directory is a common place for temporary files that may not always get cleaned up. Use the find command to locate and remove files older than 7 days:
find /tmp -type f -mtime +7 -exec rm -f {} \; |
Here’s what this does:
- /tmp : Targets the temporary directory.
- -type f : Looks only for files (ignores directories).
- -mtime +7 : Finds files older than 7 days.
- -exec rm -f {} \; : Deletes the files it finds.
Run this periodically to keep /tmp from becoming a storage hog.
Using tmpwatch for Temporary Files
If you prefer a dedicated tool, tmpwatch automates the cleanup process. For example, to delete files in /tmp that haven’t been accessed in 7 days:
tmpwatch 7d /tmp |
This is simpler than find and ensures only truly unused files are removed.
Clearing Package Manager Cache
Package managers like apt or yum often leave behind cached files after installing updates. To clean them:
- For Debian/Ubuntu (apt):
sudo apt clean |
This removes all cached .deb files from /var/cache/apt/archives.
- For CentOS/RHEL (yum or dnf):
sudo yum clean all |
Or:
sudo dnf clean all |
Finding Large Files with find
Sometimes junk files aren’t in /tmp — they’re scattered elsewhere. Use find to locate large files (e.g., over 100MB) across your system:
find / -type f -size +100M -exec ls -lh {} \; |
This helps you identify big files that might be safe to delete, like old logs or unused media.
Before deleting anything, confirm the file’s purpose. For example, don’t blindly remove files from /var, /etc, or /usr unless you’re certain they’re unnecessary. Always back up critical data before running deletion commands.
By using these commands and staying vigilant, you’ll keep your server free of junk files without risking system stability.
How Do I Locate the Folders Containing a Particular Set of Data?
When your VPS starts running low on disk space, the first step is to figure out where the bulk of your data lives. Two tools — du -sh * and ncdu — are your go-to solutions for pinpointing the heaviest directories.
Using du -sh *
Run this command in the directory you want to analyze:
du -sh * |
Here’s an example output:
2.5G logs/1.8G backups/500M cache/300M uploads/ |
This shows the size of each folder or file in the current directory. In this case, the logs/ folder is the largest at 2.5GB. Drill down further into logs/ by running:
du -sh logs/* |
Now you know the error.log file is the main culprit.
Using ncdu for Interactive Analysis
If you prefer a more user-friendly approach, install ncdu (a disk usage analyzer):
sudo apt install ncdu # For Debian/Ubuntusudo yum install ncdu # For CentOS/RHEL |
Then run:
ncdu /path/to/directory |
You’ll see an interactive breakdown of disk usage. Use your arrow keys to navigate and identify large folders or files.
These tools help you locate the biggest space hogs quickly. For example, if /var/log is eating up space, you can clear old logs. If /home/user/uploads is bloated, consider archiving or deleting unused files. By systematically analyzing your directories, you can reclaim valuable disk space without guesswork. Remember: Always verify what you’re deleting to avoid accidentally removing critical files.
How do I Prevent Disk Space Overages?
Preventing disk space overages is all about proactive management. Here’s how you can stay ahead of the curve with practical strategies and tools.
Automate Cleanup with Log Rotation and Cron Jobs
If you’ve ever run into a situation where your VPS disk space is mysteriously maxed out, log files are often the culprits. These files track everything happening on your server, which is great for debugging but not so great when they grow uncontrollably. That’s why setting up a system to manage them automatically is crucial.
Log rotation is the process of archiving old logs, compressing them to save space, and eventually deleting the ones you no longer need. Most Linux-based systems come with tools that handle this for common services, but if your specific applications don’t have log rotation configured, it’s worth setting up. This ensures your logs stay organized without eating up all your disk space.
Pairing log rotation with scheduled cleanup tasks adds another layer of efficiency. By automating these processes, you can keep your server lean and avoid unexpected crashes or performance issues caused by a full disk. Just make sure to review your setup periodically — automation is powerful, but it’s not a “set it and forget it” solution.
Set User Quotas
If multiple users or applications share your VPS, enforce disk quotas to prevent one user from hogging all the space. On Linux, use quota:
sudo apt install quota # Install quota toolssudo edquota -u username # Set quotas for a user |
Set soft and hard limits for disk usage to avoid surprises.
Monitor Disk Usage with Tools
Monitoring tools like Nagios or Zabbix can alert you before disk space becomes critical. For example, in Zabbix, create a trigger for disk usage:
Trigger: {Template OS Linux:vfs.fs.size[/,pused].last()} > 80 |
This sends an alert when disk usage exceeds 80%.
Alternatively, use simple monitoring scripts with df -h:
df -h | awk ‘$5+0 > 80 {print $6 ” is above 80% full”}' |
Run this as a cron job to notify you via email or logs.
Limit File Uploads and Cache Sizes
For web servers, limit the size of uploads or cache directories. For example, configure Nginx or Apache to restrict upload sizes:
client_max_body_size 10M; |
Or clear old cache files with a script:
find /var/cache -type f -mtime +14 -exec rm -f {} \; |
By automating cleanup, setting quotas, and using monitoring tools, you can prevent disk overages before they happen. These steps ensure your server stays lean, reliable, and ready to handle whatever comes its way.
What are the Dangers of Being Too Close to Disk Quota?
Running out of disk space isn’t just an inconvenience — it’s a recipe for disaster. When your VPS hits its disk quota, critical system functions start breaking down. For example, applications that rely on writing logs (like web servers or monitoring tools) will fail if there’s no space left. This can leave you blind to errors or security breaches.
Databases are another big risk. MySQL, PostgreSQL, and other database systems need free space to perform operations like creating temporary files or updating indexes. Without it, queries may fail, or worse, the entire database could crash, leading to downtime or data corruption. Even worse, if your root partition fills up completely, the system itself can freeze. Essential processes like cron or even SSH may stop working, leaving you unable to log in or fix the issue remotely.
To avoid these problems, always aim to keep at least 10-15% of your disk space free. This buffer ensures smooth operation and gives you room to investigate and resolve issues when storage starts running low. Remember: a full disk isn’t just a warning sign — it’s a ticking time bomb.
So, What Do I Do if I'm Running Out of Space?
When your VPS is running out of disk space, panic won’t help — but a clear plan will. Here’s a step-by-step guide to reclaiming space and getting your server back on track.
Clean Up Temporary Files
Start by clearing out temporary files that are no longer needed. Use the find command to locate and remove old files in /tmp or other temp directories:
find /tmp -type f -mtime +7 -exec rm -f {} \; |
This deletes files older than 7 days. Be cautious not to touch critical system files.
Rotate and Delete Old Logs
Logs can grow exponentially, especially on busy servers. Use logrotate or manually clean up logs. For example:
sudo find /var/log -type f -name “*.log” -exec truncate -s 0 {} \; |
This truncates log files to zero size without deleting them, ensuring services aren’t disrupted.
If you’re sure old logs aren’t needed, delete them:
sudo rm /var/log/*.gz |
This removes compressed log files, which often accumulate over time.
Identify and Remove Large Files
Use du -sh * or ncdu to find large files. For example:
du -sh /home/* |
If you spot a massive file or directory that’s no longer needed, remove it:
rm -rf /home/user/unused_backup.tar.gz |
Migrate Data to External Storage
For non-critical data like backups or media, offload files to external storage. Use tools like rsync to move data to an external drive or cloud storage:
rsync -avz /path/to/large/files/ user@remote:/backup/ |
Then delete the local copies to free up space.
Add Additional Disks
When your VPS starts running out of space, adding an extra disk can be a lifesaver. This approach allows you to offload bulky files, such as backups, media, or logs, onto a secondary storage device. Most hosting providers make it easy to attach additional disks to your VPS through their control panel. Once added, you can move large files or entire directories to the new disk to free up space on your primary drive.
This method not only helps with organization but also improves performance by reducing clutter on your main disk. Just remember to update any app configurations that rely on the old file paths. Adding a disk is a scalable solution that buys you time and keeps your server running smoothly.
Final Thoughts
Managing disk space on your VPS isn’t just a task — it’s an ongoing responsibility. Regular monitoring and proactive cleanup can save you from costly downtime, performance issues, and security risks. Remember, prevention is always easier than fixing problems after they’ve spiraled out of control.
Don’t wait for your server to hit 100% usage before taking action. Start implementing the tools and strategies outlined in this article today — set up log rotation, automate cleanup scripts, and keep an eye on disk usage with monitoring tools. Your future self (and your users) will thank you for keeping your server running smoothly. Take control of your disk space now — it’s one of the smartest investments you can make for your VPS.

Ludjon, who co-founded Codeless, possesses a deep passion for technology and the web. With over a decade of experience in constructing websites and developing widely-used WordPress themes, Ludjon has established himself as an accomplished expert in the field.
Comments