How to: Erase a log file in Ubuntu
How to: Erase a log file in Ubuntu
Ever had this huge error log, full of nightmares and bad memories? Well, once you’re done fixing the problems then you’re stuck with megs if not gigs worth of bad memories that perhaps you wish to get rid off. Well, in my case one of my errors sent so much information to the log file it was on the gigs arena. This obviously becomes an issue as much of that information is not important to me any more and it can have a performance impact on the system.
Usually I would move the original file to a backup location and create a new one. The issue with this approach is that the permissions or attributes of the original file need to be copied over to the new one… more work basically. So I did some research and it is possible to simply truncate your log file so that all you’re doing is getting rid of the data within and keeping all the attributes and the like untouched.
There are a couple of ways to do this: You can do some fancy output redirection or you could use the truncate command. Either way the result is the same and all it takes is one command line. Here it goes:
Option 1: Redirect output to the file to clear it:
If you simply redirect null output to the file, basically you’re wiping it clean. Simply do the following:
>error.log
Option 2: Use the truncate command:
For those who feel more at home with a traditional command instead of ninja magic:
truncate -s0 error.log
Love
Can we use Let's Encrypt, the free and open certificate authority?
Hola! gracias por la info, me sirvió el comando sacandole el nombre del server. En mi caso, fue una migración…
Yes 3rd option helped me too. I removed the WC key Values from config file then started working.
I know this is from 2014. But really, thank you!