Take the 2-minute tour ×

I have a very large error log file( around 200 MB),in a remote server

I want to delete some last 125,000 lines from it, using command prompt

How can i do this

share|improve this question

closed as off topic by skaffman, bmargulies, Thomas M. DuBuisson, Bo Persson, Robert Harvey Aug 3 '11 at 21:31


You want to delete the last 125000? Why do you want to delete the most recent lines? –  Jacob Aug 3 '11 at 16:34
Is not important.I just wants to know , how can i delete some few lines from the error log –  Linto Aug 3 '11 at 16:39
add comment

2 Answers

up vote 1 down vote accepted
head -n -125000 logfile

will get you all but the last 125000 lines from a file named logfile. If there are less than 125,000 lines you will get nothing.

Perhaps you should be looking into logrotate instead.

share|improve this answer
add comment

If you want to get the most recent 100k lines into the old log, I would do this:

tail -n 100000 oldlog.log > tmplog.log && rm oldlog.log && mv tmplog.log oldlog.log

CAUTION: this deletes the original log.

share|improve this answer
add comment
