How to delete all error_log files on a cPanel server

This command will search in all /home/*/public_html directories (also in subdirectories) for error_log files:

/usr/bin/find /home/*/public_html -type f -name error_log -exec du -sh {} \;

Usage example:

root@srv01 [~]# /usr/bin/find /home/*/public_html -type f -name error_log -exec du -sh {} \;
4.0K /home/cpuserdemo/public_html/error_log
4.0K /home/cpuserdemo/public_html/wp-includes/ID3/error_log
9.0K /home/cpuserdemo/public_html/wp-includes/theme-compat/error_log
4.0K /home/cpuserdemo/public_html/wp-includes/SimplePie/error_log
4.0K /home/cpuserdemo/public_html/wp-includes/SimplePie/Cache/error_log
root@srv01 [~]#

Many times you will want to see the error+log files that use the most space. For this, sort the results. The command is:

/usr/bin/find /home/*/public_html -type f -name error_log -exec du -sh {} \; | sort -n

Do you need to list only the error_log files bigger than 50MB? Use this command:

/usr/bin/find /home/*/public_html -type f -name error_log -size +50000k -exec du -sh {} \;

Notice that depending on your number of files and accounts, these commands can run for a long time.

Now let’s see how we delete these files. To delete all the founded error_log files, use:

/usr/bin/find /home/*/public_html -type f -iname error_log -delete

To delete error_log files larger than 50MB, use:

/usr/bin/find /home/*/public_html -type f -iname error_log -size +50000k -delete

Want to add a cron job that will delete error_log files? Use the crontab -e command to edit the server jobs.

crontab -e

Then add the line (the cron job will run every 2 hours):

0 */2 * * * /usr/bin/find /home/*/public_html -type f -name error_log -delete

Exit the crontab editor by CTRL + X. Confirm the changes.

Read more articles

  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

How to fix IP Missing issue on cPanel/WHM

We are here to help you with solving the problem of Missing IP Server in list accounts. The...

Domain names are not showing in WHM

We were unable to see any domains listed under WHM -> List Accounts. However, we can see the...

How to Start/Stop or Restart Apache server

Apache is the HTTP server that is freely available over the internet. It is a kind of software or...

How to install Attracta SEO Tools plugin

RequirementscPanel/WHM needs to be installed on your server. Step 1: SSH into your server and go...

How to Install CpCleaner in cPanel through SSH?

Installation Run the following shell commands as root via SSH: wget -O cpc-1.0.3.tar...