Possible Duplicate:
Logrotate configuration for httpd (CentOS)

can I delete error log files in apache. Any issue? Because it eats my server space

marked as duplicate by Ward, rnxrx, Magellan, Chris S Oct 12 '12 at 16:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Oct 11 '12 at 17:06

This question came from our site for professional and enthusiast programmers.


If you must clear the log file, do

cp /dev/null /var/log/file


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.

  • 4
    I like doing :>/var/log/file. It's quick, and looks like a bird. – Tom O'Connor Oct 12 '12 at 18:05

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.

  • 2
    A graceful restart (SIGUSR1) would generally be preferable to a "drop all connections and restart RIGHT FREAKIN' NOW!" (SIGHUP). – voretaq7 Oct 12 '12 at 17:11
  • 1
    Thanks @voretaq7 I didn't find out those information on the doc. Editing answer. – aif Oct 12 '12 at 17:34