Forums

How to automatically delete/clear the log file from a task

I have a task which runs every day at a specific time. I noticed that the logfile is not cleared, the info of the latest run is added to the same logfile, which makes the logfile to large and difficult to read. Is there a way to clear the logfile automatically (e.g. before a new run starts) ?

You can use something like this:

echo '' > /var/log/log-file-.log

to clear the log file.

Hello there! echo '' > /var/log/log-file-.log used to work. But lately (last week and also now October 3, 2024) it does not work anymore. Running it from the console with the actual name of the log file resulted in "Permission denied". Has something been changed, or I missed something? Is there an alternate method to do it now? Thanks in advance for your kind pointers.

Try lsing the /var/log directory before echoing to the file to update the local view of the files.

Many thanks for your kind hints! It works!

Let us know if you need more help.