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