I read several question for the mentioned topic, but I'm not sure if they really answer the question for my problem.

I have an application running and I redirect the output to a log file, i.e.,

nohup ./start.sh ./config/s.properties >./logs/app.log 2>&1 &

The file is now 80GB in size and I would like to delete it. Most of the answers here suggest not to delete it, because the data will still be written to the "deleted" file. Answers suggest to use logrotate instead, but I'm wondering if logrotate works with redirected output?

If it does work, what would the configuration look like? Do I need any postrotate command? I should mention that it is impossible for me to stop and restart the running application, thus I would just like to "steal" the file and let the running application write to a new one.

If logrotate is not the solution, what should I do - again I cannot stop and restart the running application - so that I can reduce the file-size?

Thanks for any help!

PS: Just to mention the application is running on a Debian8 64 OS

  • If you mv the log file, and send SIGHUP to your application, does it start writing to a new log file?
    – DopeGhoti
    May 15, 2018 at 16:06

1 Answer 1


If you delete the file while a process has an open file handle on it, Linux will keep the contents alive on disk until the process closes the file handle. If you don't want to keep the existing content of the long, you can simply truncate it:

> ./logs/app.log 
# or
truncate -s 0 ./logs/app.log

This should clear the existing contents of the file.

  • Perfect and the process will still write to this file, because the file is truncated and not deleted - correct? Is there any way to do this with logrotate as well (I saw a copytruncate option, but answers I read seem to say that it does not work if the redirect is using create > instead of append >>.
    – Philipp
    May 15, 2018 at 17:41
  • I just tried it and it didn't work, the file-size stays the same and the process keeps writing to it.
    – Philipp
    May 15, 2018 at 18:31
  • @Philipp odd, it worked fine for me. I ran yes > foo in one terminal, and ls -sh foo; df -h /; > foo; ls -sh foo; df -h / in another, and both file size and disk usage were lower after > foo.
    – muru
    May 16, 2018 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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