6

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
  • 233

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,301
  • 1
  • 15
  • 22
9
$ sudo truncate -s 0 /path/to/log.log
Progrock
  • 486