Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 :)

share|improve this question
3  
Have you considered using logrotate? –  jordanm Nov 1 '12 at 0:45
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.