Servers are your virtual home and, just like your real home, they can become cluttered with unwanted junk. In the case of servers, it’s not trash but data you have to kick to the curb every once in a while.
Without a regular clear out, data accumulates until it fills the server’s storage devices. Servers need to be able to write data to their hard drives. When there’s no space to store new stuff, the performance takes a hit and some software will stop working altogether.
We recommend that you keep at least 10 percent of the server’s storage free, which means you will occasionally have to check disk space and find unused data to delete. In this article, we show you how to do just that with cPanel and the disk management tools on your Linux® server.
How to Manage your Hard Drive Space in cPanel
There are a couple of prerequisites you should know about before we explain how to manage hard drive space.
- You need to be able to log in as the root user to manage files outside of your home directory. While any user can manage their own files, only the root user can monitor and delete files owned by other users.
- You will need to log in to your server using SSH to run file management commands.
When you’re concerned about disk space, WHM’s Disk Usage tool should be your first destination. It checks Linux disk space and displays the results in an intuitive interface. You will find it under System Health in the WHM sidebar menu.
Disk Usage shows a list of storage devices, their sizes, and how full they are. The number of devices and their names differ depending on the configuration of the server, but if they are more than 90% full, you should delete old data.
In the above image, we see that one of the hard drives on this server is dangerously full. To find out which files are causing the problem, we log in with SSH and use the command line to investigate.
Check Disk Command
First, we’ll use the df tool to check disk space on the server’s hard drives. It provides more or less the same information as Disk Usage, but it’s helpful if you want to start your investigation on the command line instead of in WHM.
Run the command:
The -h flag tells df to use human-readable units instead of spitting out confusing byte counts. The output looks something like this:
You can ignore the tmpfs devices; they’re virtual disks stored in memory and may not be present on your server. We’ve underlined the interesting entry: the disk named /dev/vda1, which is mounted on the root (/) of the filesystem, is 92 percent full.
Now we have verified that a disk is nearly full, we have to find out which files are responsible. For that, we use du:
du -sh /*
The -s option produces a summary of the data so we can more easily identify large files and directories. As before, -h tells du to output sensible units.
At the end of the command is a file argument. In the last step, we found the overfull drive was mounted on “/”, so that’s where we start our search. The * means everything inside the / directory.
Here’s a section of the output from du.
As you can see, the /var directory consumes 40 GB, dwarfing the amount of data in the other directories. So, we run du again on /var.
It’s difficult to spot the largest files when there are lots of them, so we’ll use sort to print big files first and head to grab the top 10.
du -sh /var/* | sort -rh | head -n 10
We’ve found the culprit! There is an enormous 39GB file in /var.
Now we have to decide whether we can safely delete it or not. Deleting a file is irreversible, so you should do some research to verify that it doesn’t contain data that matters to your or the server.
We know that it’s safe to remove /var/largefile.log, so we can delete it with the rm command:
rm -f /var/largefile.log
If you want to delete a directory of files, use this command instead:
rm -rf /var/largedirectory
The -f option means “force”. It tells rm to delete files without asking permission first. The -r option means “recursive,” and it makes rm delete everything inside a directory.
If we go back to WHM’s Disk Usage page, we see that the device is no longer full, and the problems caused by the lack of storage space have been resolved.
Disk space problems are rarely caused by a single large file. In reality, you’ll be dealing with lots of smaller files, but you can use the same process of identification and deletion with cPanel and the command line to find and remove any quantity of unwanted data.
As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You’ll find us on Discord, the cPanel forums, and Reddit.