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!! Note that, this will remove all those error_log files.. If you find any particular file or files causing continuous issues, change the find location accordingly.

Let me know if you have any questions.


Post navigation

Arunlal Ashok

DevOps Engineer. Linux lover. Traveller.
Always happy for an open discussion! Write to arun ((@)) crybit ((dot)) com.

5 thoughts on “How to remove large error_log files from cPanel accounts?

  1. thank u,
    googled and found many commands for setting a cron job to delete that file, but only yours worked.


  2. I’d want to use this command instead, so I don’t wipe out my error history all the time:
    find /home -type f -iname error_log -size +10M -delete

    This command will only remove large error log files (10Mb in this case, you can change it to whatever you want).

    Also, your current cron line means “every hour at 10 past on Friday”. I think you probably mean “once a week at 5:10m on Friday” which would be “10 5 * * 5”.

    The version of the find I have above could happily be run several times a day if the site wasn’t too large. If the error_log in question grows really quickly, it’s not too hard to write a PHP function that does a quick check every page hit (cost is just one ‘stat’ system call, so very small). Hope this helps someone out!

  3. If we delete some log file, then some of the framework got error.
    My suggestion is, instead of delete, if we replace those log file with 0KB file with same file name then it will save the storage space and also your website will work without any issue.

    Note: i am not sound good in command line, if any one can provide the command for my above solution which is really help full.

    command require:
    1. finding error_log file
    2. overwrite those error_log file with zero KB.

    1. You can create a zero-size file using the truncate command:

Leave a Reply

Your email address will not be published.