5

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

Kvvaradha
  • 223

2 Answers2

16

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.

NZD
  • 3,231
  • 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 05 '15 at 05:44
  • Use sudo sh -c ' echo > /path/to/file' http://stackoverflow.com/questions/82256/how-do-i-use-sudo-to-redirect-output-to-a-location-i-dont-have-permission-to-wr – Progrock Dec 05 '15 at 06:29
  • @Kvvaradha See my updated answer. – NZD Dec 05 '15 at 07:03
9
$ sudo truncate -s 0 /path/to/log.log
Progrock
  • 486
  • 1
    I used this: alias clog='sudo truncate -s 0' then just use clog error.log. Nice, thanks :-D –  Aug 05 '20 at 08:57