1

This question already has an answer here:

I am new to Ubuntu. I can find my error log here in var/log/apache2/error.log. but i couldn't clear it. i tried to change the permission to edit the content. But couldn't achieve it.

Please help me to remove it. I have read some question previously asked. but it does-not help me .

this one I read https://askubuntu.com/questions/574725/how-to-clear-system-logs-in-ubuntu.

Here is my terminal screen-shot:

enter image description here

marked as duplicate by David Foerster, Eric Carvalho, Videonauth, RPiAwesomeness, muru May 19 '16 at 20:15

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.

6

Most files in /var/log are owned by root.

So, if you want to modify them, you will have to use sudo.

To clear the error file, give command:

sudo bash -c 'echo > /var/log/apache2/error.log'

If that doesn't work, then very likely the apache process keeps the file locked and you have to stop apache before you can clear the file. This goes as follows:

sudo service apache2 stop
sudo bash -c 'echo > /var/log/apache2/error.log'
sudo service apache2 start

Note: You can't use sudo echo > /var/log/apache2/error.log here, because sudo executes the echo command but the redirect to error.log is done under the process of the user, which doesn't have elevated privileges. That's why I pass the whole command to bash, which is then executed by sudo.

  • i tried it, it prevents the permission. I don't know how to provide access. and here i added a screen-shot in my question by editing it – Kvvaradha Dec 5 '15 at 5:44
  • Use sudo sh -c ' echo > /path/to/file' stackoverflow.com/questions/82256/… – Progrock Dec 5 '15 at 6:29
  • @Progrock thanks for that, updated my answer. – NZD Dec 5 '15 at 7:03
  • @Kvvaradha See my updated answer. – NZD Dec 5 '15 at 7:03
  • I solved it. Thanks for your answer. – Kvvaradha Dec 5 '15 at 7:05
4
$ sudo truncate -s 0 /path/to/log.log

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