How to remove large error_log files from cPanel accounts?

Error logs on cPanel accounts may consume a lot of disk space on your server. It may create disk space issues, if your server contains a lot of accounts. Okay, here I’m going to explain “how we can remove those error logs from the home directory of cPanel accounts in a single command or using a CRON JOB for automatic removal.”

Here we can use the find command to list and remove them from the home directory. We already discussed the find command usage in one of my previous article. Please refer to this topic for more details, find command usage in Linux.

Here we go!!

1. SSH to server as root user.
2. List the Error Log files with its disk space usage details.

# find /home -type f -iname error_log -exec du -sh {} \;

-type : Specify the type to find.
-iname : Specify the name to find.
-exec : Execute the “du -sch” and lists the output with file size.

Sample output

# find /home -type f -iname error_log -exec du -sh {} \;
4.0K    /home/serf/public_html/wp-admin/error_log
4.0K    /home/serf/public_html/wp-includes/error_log
16K     /home/12erf/public_html/error_log
8.0K    /home/12erf/public_html/wp-content/plugins/LayerSlider/wp/error_log
4.0K    /home/tuy/public_html/wp-content/plugins/LayerSlider/error_log

How to remove those error_log files?

Find command has an option “-delete” to remove those contents instantly. Here I’m explaining the command to remove those error log files:

# find /home -type f -iname error_log -delete

-delete : This switch remove the outputs from the find command.

Yup, that’s it dude!! All of them were removed from your server. Check the disk usage now!

Do you want to execute this command periodically? If so, please set a cronjob for this. I’m sure you all have good knowledge in job scheduling using Crontab. You can refer this topic for more details, 10+ examples of Job Scheduling Using Crontab

Create a cron by using the following command:

/bin/find /home -type f -iname error_log -delete


10 * * * 5 /bin/find /home -type f -iname error_log -delete

That’s it!!

Let me know if you have any questions.

Arunlal Ashok

Linux Server Administrator. I’m managing Linux servers since 2012. I started this blog to share and discuss my ideas.

Any questions? Write to arun (@)

You may also like...

Leave a Reply

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