Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to erase the contents of the file error.log (nginx error log file), but I don't want to actually delete the file.

is this possible?

running ubuntu

share|improve this question

You can use this:


(typed just like that - an empty output redirection)


truncate -s0 error.log
share|improve this answer
@Ignacio: If the file already exists, either will truncate it. If the file doesn't exist, either will create it. – Dennis Williamson Dec 4 '10 at 3:21
You're right, my bad. – Ignacio Vazquez-Abrams Dec 4 '10 at 3:24
The last option worked for me, for some reason sudo >error.log didnt work for me (ubuntu 12.04) – davidkonrad May 19 '14 at 10:38
@davidkonrad: You would have to already be root for the redirection to work since it's performed before sudo takes effect. Or you can do sudo bash -c '>error.log' – Dennis Williamson May 19 '14 at 10:56
OK, didnt knew that. Thank you for clarification! – davidkonrad May 19 '14 at 11:01

You'll confuse the daemon. Erase the file then send SIGHUP to nginx.

share|improve this answer
SIGHUP? Can't I shut nginx down, purge the file, then start? I want to know how to erase the file for knowledge sake also. – user27449 Dec 4 '10 at 3:14
If you wanted to, sure. But that would disrupt service. – Ignacio Vazquez-Abrams Dec 4 '10 at 3:15
I think both a null redirection and a truncate are atomic, so as long as no seeking is going on (especially if the only operation that's occurring is appending) it shouldn't be disruptive. – Dennis Williamson Dec 4 '10 at 3: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.