Bash edit file and keep last 500 lines

Posted by icelizard on Server Fault See other posts from Server Fault or by icelizard
Published on 2010-05-21T09:15:01Z Indexed on 2010/05/21 9:21 UTC
Read the original article Hit count: 415

Filed under:
|
|
|

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.

I was thinking of something along the lines of

tail -n 500 filename > filename

Would this work?

I also not sure how to loop through a directory in bash

Thanks in advance.

© Server Fault or respective owner

Bash edit file and keep last 500 lines

Posted by Lizard on Stack Overflow See other posts from Stack Overflow or by Lizard
Published on 2010-05-21T09:11:21Z Indexed on 2010/05/21 9:20 UTC
Read the original article Hit count: 415

Filed under:
|
|
|

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.

I was thinking of something along the lines of

tail -n 500 filename > filename

Would this work?

I also not sure how to loop through a directory in bash

Thanks in advance.

© Stack Overflow or respective owner

Related posts about bash

Related posts about directory-loop