How to Free up disk space on cPanel servers

Sometimes our servers include small hard drives or our users simply consume lot of disk space. In this situations when your drives are pretty close to be totally full, you may end up having writing error on partitions like /home /tmp or /boot. That’s why today we will teach you How to Free up disk space on cPanel servers.

This tutorial is also useful for general Linux systems without any control panel like cPanel.

Start now: Free up disk space on cPanel

Check your disk space usage using df command:

df -ah

Check how much each directory is using, except for /backup directory, which is usually a secondary hdd or network storage drive:

du -shc /* --exclude='backup' --exclude='proc' --exclude='virtfs'

If you don’t have backup on an external drive or use the same primary disk for both things (OS and backups), use this command:

du -shc /* --exclude='proc' --exclude='virtfs'

Check size and remove Fantastico backups:

du -shc /home/*/fantastico_backups
rm /home/*/fantastico_backups -rfv

Delete temporary cPanel File Manager files

When your cPanel users upload files using the File Manager tool from cPanel, this causes cPanel to create temporary files that may not be removed after the upload.You can check the disk space usage for this and remove all those temp files using this commands:

du -shc /home/*/tmp/Cpanel_*
rm -fv /home/*/tmp/Cpanel_*

Delete user’s error_logs from inside public_html directory

rm /home/*/public_html/error_log -fv
rm /home/*/public_html/*/error_log -fv
rm /home/*/public_html/*/*/error_log -fv
rm /home/*/public_html/*/*/*/error_log -fv
rm /home/*/public_html/*/*/*/*/error_log -fv

Delete Apache logs

This is another way to Free up disk space on cPanel systems

du -shc /usr/local/apache/logs/*

Check out which are the most heavy files and if you don’t need them, just delete it using rm command.

Delete old Backups inside /home directory

Sometimes System Administrators generate full backups from the linux shell, and those are stored inside the main /home directory of your cPanel box, let’s check out if there is any and what’s the total size:

du -shc /home/*.tar.gz
rm /home/*.tar.gz -fv

Delete full backups inside /home/user/ directories

du -shc /home/*/backup*.tar.gz
rm /home/*/backup*.tar.gz -fv

Find and delete all core dump files generated by app errors

Sometimes your web applications hit a bug or fail because of system errors, in this cases core dump files are generated inside each user’s directory. That’s normal because core dump files can be used to inspect and debug web application errors, however… the downside of this is the fact that this files can get really big in terms of disk usage, sometimes lot of GBs.

First, update your file database:

locate -r /core\.[0-9] | grep /home | egrep -v 'virtfs|php|sql|ini'

This will show you a few or lot of results, inspect the files carefully before start deleting, because you may find valid (non core dum files) inside.

Once you are ready, you can add xargs command to the previous one we used, this is how it should look to delete all those files:

locate -r /core\.[0-9] | grep /home | egrep -v 'virtfs|php|sql|ini' | xargs rm -fv

Search for files bigger than 100MB inside /home directory

find /home/*/public_html/ -type f -size +100M -exec ls -lah {} \; | awk '{ print $9 ": " $5 }'

Decrease the reserved disk space

By default most Linux Operating Systems reserve 5% of the disk space from each partition for root user, so you can still login to your box even if your disk space is totally full.

On a 800 GB drive you may notice that 40 GB are reserved (5% we told you before), this may not be too much, but it’s something you can tweak if you need.

On a 2TB drive, your reserved disk space will be around 100GB, see… that’s way too much than 40GB from the previous example and it may help in case you need some extra space.

tune2fs can be used for this purpose:

tune2fs -m 2 /dev/sda1

In this example, tune2fs will reduce your reserved disk space from 5% to 2%. But before you run this command, please read the tune2fs manual and understand what you are doing. Also, never do this in production enviroments before previous sucessfull tests on a test box.

You can read more on how to reduce reserved blocks on this post: Free Disk Space Reducing Reserved Blocks


After following all this steps, you should be more than ready to Free up disk space on cPanel and general Linux based servers. Most of the steps involved are not dangerous for system related services. If after all this commands you can not free up disk space, maybe it’s time to get an additional/secondary drive to host your content.

Further reading:

About the Author: Martin Keler

Leave a Reply

Your email address will not be published. Required fields are marked *