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


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
  • @Kvvaradha See my updated answer. – NZD Dec 5 '15 at 7:03
$ sudo truncate -s 0 /path/to/log.log
  • I used this: alias clog='sudo truncate -s 0' then just use clog error.log. Nice, thanks :-D – Pixel Aug 5 '20 at 8:57

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