Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • It's a nice theory, but it doesn't actually work on any system I've tried it on. The file does not actually get truncated and the program continues to append to it as before. (And yes, that's even with the redirection done via >>.) ((BTW, this answer was already given previously.)) Commented Oct 24, 2014 at 0:10
  • 1
    … as discussed in logrotate won’t truncate original file (on our Unix&Linux site). Also, echo /dev/urandom >> /tmp/temp.log will write 13 deterministic characters to /tmp/temp.log and then immediately exit. Did you mean cat /dev/urandom? Commented Oct 24, 2014 at 0:36
  • 2
    Just tested here, and it seems to work. Content of file is copied to new log file. Original file is kept open by process and is truncated (size now shows 0). Commented Jan 21, 2015 at 9:09
  • 1
    Be careful about the possible data loss with copytruncate. Commented Oct 25, 2016 at 22:55
  • 1
    +1 although "Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost." Commented May 27, 2017 at 7:09