Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

We have an apache server running on linux writing to a log file that is getting really large (access_log). Our server will begin running out of space. Is there a way to delete or truncate the file without restarting the server (we don't want any down time).

share|improve this question

migrated from Nov 18 '09 at 22:43

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

5 Answers 5

How to reset your log files

Sooner or later, you'll want to reset your log files (access_log and error_log) because they are too big, or full of old information you don't need.

access_log typically grows by 1Mb for each 10,000 requests.

Most people's first attempt at replacing the logfile is to just move the logfile or remove the logfile. This doesn't work.

Apache will continue writing to the logfile at the same offset as before the logfile moved. This results in a new logfile being created which is just as big as the old one, but it now contains thousands (or millions) of null characters.

The correct procedure is to move the logfile, then signal Apache to tell it to reopen the logfiles.

Apache is signaled using the SIGHUP (-1) signal. e.g.

mv access_log access_log.old
kill -1 `cat` 

Note: is a file containing the process id of the Apache httpd daemon, Apache saves this in the same directory as the log files.

Many people use this method to replace (and backup) their logfiles on a nightly or weekly basis.

share|improve this answer
What about logrotated ? – LiraNuna Oct 5 '09 at 19:38
I can't find the file in /var/log/httpd, any ideas? – erotsppa Oct 5 '09 at 19:57
Not sure.. Have you done a directory search? – madcolor Oct 5 '09 at 20:07
Under /var/run/ Thanks! – erotsppa Oct 5 '09 at 20:33

log rotation is the long-term solution but the answer to your immediate question is to truncate the file something like this:

sudo cat /dev/null > /var/log/httpd/access_log

i'm assuming you're not logged in as root and assuming the location of your log file but you should be able to adjust the command as needed and quickly truncate an open log file w/o touching your running apache processes.

share|improve this answer
at least on my ubuntu 12.04 that doesn't work: the sudo applies to cat, but NOT to the file redirection. I used to sudo truncate -s0 logfile. – drevicko Jun 26 '13 at 8:03

Zero the logfile...

# :>filename
share|improve this answer
doesn't this require your user to have write access to the log file? Generally that's not the case... – drevicko Jun 26 '13 at 8:04
Based on the prompt, I'd say that he's logged in as root. – Ladadadada Jun 26 '13 at 9:23

If you want to truncate/zero a log file to which you don't have write access, you can do

sudo truncate -s0 logfile
share|improve this answer
truncating the file doesn't work – c4f4t0r Feb 23 at 15:08
@c4f4t0r can you elaborate? – drevicko Feb 24 at 23:55

simply you can make first $cat filename >bkp_filename than it will create copy of "filename" than do nullify original file like $>filename it will reduce to zero size,now make zip to bkp_filename like $gzip bkp_filename so it will provide more size and your mount point is green now

share|improve this answer
If you're running out of space, creating a copy of the logfile will likely make the situation worse, rather than better. Additionally please try to format commands by enclosing them in backticks ```. Thanks! – HBruijn Sep 8 at 16:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.