2

I am making a simple IRC bot in bash and I want prevent its log from growing to infinity. For example it could be shortened always when reaching set number of lines. How can I do that easily? For example by cutting the file with removing first line(s)?

If possible, I would like to avoid sed/awk this time :)

  • 3
    Have you considered using logrotate? – jordanm Nov 1 '12 at 0:45
2

As jordanm said, logrotate is best. But if you do want to roll your own,

tail -n 50 logfile.txt > logfile.new
mv logfile.new logfile.txt

would save only the last 50 lines.

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.