How to Delete Every error_log File on a cPanel Server

Have you ever needed to free disk space on a cPanel server with a lot of customer accounts on it? An easy way to free up disk space is deleting error_log files. We’ve seen customer accounts with error_log files in the range of 5-10GB depending on the number of errors being logged from their websites. Here is a quick and easy set of commands to check error_log files and delete them, if necessary.

Please be sure to have backups in case you need to reference the contents of the logs! Also, please note these commands can take a long time to run on resource-limited servers.


Locating error_log Files on cPanel Servers:

Locate All error_log Files:
root@server [~]# find /home/*/public_html -type f -name error_log -exec du -sh {} ;

Locate All error_log Files and Sort by Disk Size:
root@server [~]# find /home/*/public_html -type f -name error_log -exec du -sh {} ; | sort -n

Locate All error_log Files Over 100MB:
root@server [~]# find /home/*/public_html -type f -name error_log -size +100000k -exec du -sh {} ;


Deleting error_log Files on cPanel Servers:

Delete All error_log Files:
root@server [~]# find /home/*/public_html -type f -iname error_log -delete

Delete All error_log Files Over 100MB:
root@server [~]# find /home/*/public_html -type f -iname error_log -size +100000k -delete


Cron-Based Deletion of cPanel Server Error Log Files

To set up a cronjob to run one of the two deletion commands above on a scheduled basis, you can do the following:

root@server [~]# crontab -e

Which will open the crontab for root, then insert at the bottom of the file this command to delete all error_log files every day at 11PM server time:

* 23 * * * find /home/*/public_html -type f -iname error_log -delete

Related: Learn how to import and export databases over the command line.


Disclaimer: WebCitz, LLC does not warrant or make any representations concerning the accuracy, likely results, or reliability of the information found on this page or on any web sites linked to from this page. This blog article was written by David W in his or her personal capacity. The opinion(s) expressed in this article are the author's own and may not reflect the opinion(s) of WebCitz, LLC.