Server Fault is a question and answer site for system and network administrators. 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 tried to clear the content of error.log file on my apache server with commands

sudo >error.log

sudo truncate -s0 error.log

But in both cases I got -bash: error.log: Permission denied.

I tried the same thing while stopping apache, but still got the same message. After that I tried to clear it with sudo nano error.log and was able to remove everything.

So why was not I able to clear the log properly?

share|improve this question
up vote 11 down vote accepted

You should try this :

sudo sh -c ">/var/log/apache2/error.log"
share|improve this answer
Can you please explain what does this command do? – Salvador Dali Mar 18 '14 at 0:47
It runs an inline sh (shell) command under sudo context. Actually this inline sh command clears Apache error log (as you know) – krisFR Mar 18 '14 at 0:50
My guess is that > is not a command without an interpreter like sh or bash – krisFR Mar 18 '14 at 0:59
However your sudo truncate... command should work...That is the real thing i cannot explain by now – krisFR Mar 18 '14 at 1:07
Redirection operators are evaluated by your local shell before the sudo command even runs. sudo > foo opens the file foo for writing, then runs the command sudo . If you put it inside quotes or escape the redirection operator, then it is evaluated within the context of the sub-shell. – Zoredache Mar 18 '14 at 1:16

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.