Possible Duplicate:
Logrotate configuration for httpd (CentOS)
can I delete error log files in apache. Any issue? Because it eats my server space
Possible Duplicate:
Logrotate configuration for httpd (CentOS)
can I delete error log files in apache. Any issue? Because it eats my server space
If you must clear the log file, do
cp /dev/null /var/log/file
or
echo > /var/log/file
That truncates the file without closing any open file handles.
Edit: Using logrotate
to deal with the files is the better long-term solution. Truncating the file should be an emergency measure.
I would rather recommend going for logrotate in stead of deleting the old log files straight away. You might need them later for debugging something or to find out the pattern when system was running fine, for comparison purpose.
There is a reason that backup and recovery are so sought after. However if this is not any production server or something important, I wouldn't worry about deleting them.
If you are not going to use them you can delete it. I would recomend you to delete all logs but not the current one, and if you can I should use log rotate.
If in use, deleting the log will make apache reload to re-open the just deleted file.
What you can try is indeed logrotate, or try to empty the file. I think you'll need to SIGUSR1
apache though.
This link may help.
Edit: Just tested:
# > /var/log/apache2/access.log
# tail -F /var/log/apache2/access.log
.. Still prints lines ....
# rm /var/log/apache2/access.log ; touch /var/log/apache2/access.log
# tail -F /var/log/apache2/access.log
.. displays nothing ....
# kill -USR1 $(pidof apache2)
# tail -F /var/log/apache2/access.log
.. prints lines again ....
Edit2: thanks @voretaq for further info about signals on apache. SIGUSR1
is indeed less violent than SIGHUP
.