title: Bash edit file and keep last 500 lines
body: <p>I am looking to create a cron job that opens a directory loops through all the logs i have created and deletes all lines but keep the last 500 for example.</p>
  
  <p>I was thinking of something along the lines of </p>
  
  <p><code>tail -n 500 filename &gt; filename</code></p>
  
  <p>Would this work? </p>
  
  <p>I also not sure how to loop through a directory in bash.</p>