This command will search in all /home/*/public_html directories (also in subdirectories) for error_log files:
find /home/*/public_html -type f -name error_log -exec du -sh {} \;
Usage example:
root@web [~]# find /home/*/public_html -type f -name error_log -exec du -sh {} \;
4.0K /home/tolomike/public_html/error_log
4.0K /home/tolomike/public_html/wp-includes/ID3/error_log
9.0K /home/tolomike/public_html/wp-includes/theme-compat/error_log
4.0K /home/tolomike/public_html/wp-includes/SimplePie/error_log
4.0K /home/tolomike/public_html/wp-includes/SimplePie/Cache/error_log
root@web [~]#
Many times you will want to see the error+log files that use the most space. For this, sort the results. The command is:
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:
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:
find /home/*/public_html -type f -iname error_log -delete
To delete error_log files larger than 50MB, use:
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 day at 02:30):
30 2 * * * find /home/*/public_html -type f -name error_log -delete
Exit the crontab editor by CTRL+X. Confirm the changes.
Every server should use this! Log files can be a pain when they eat up space. Thanks very much!