title: Shell Script to write to a file upto a certain point and then keep overwriting the file
body: <p>I am trying to write a shell script , which will write the output of another script in a file and it will keep writing to that upto a certain point and then it will overwrite the file so that file size will remain within a well bounded range.</p>
  
  <pre><code>while true
  do
      ./runscript.sh &gt; test.txt
      sleep 1
  done
  </code></pre>
  
  <p>I have tried to use infinite loop and sleep so that it will keep overwrite that file.</p>
  
  <p>But, it shows a different behaviour. Till the point command is running , the filesize keeps on increasing. But, when i stop the command, the file size get reduce.</p>
  
  <p>How can i keep overwriting the same file and maintain the file size along with it.</p>