Retrieve last 100 lines logs

Surabhi picture Surabhi · May 2, 2016 · Viewed 357.3k times · Source

I need to retrieve last 100 lines of logs from the log file. I tried the sed command

sed -n -e '100,$p' logfilename

Please let me know how can I change this command to specifically retrieve the last 100 lines.

Answer

Steephen picture Steephen · May 2, 2016

You can use tail command as follows:

tail -100 <log file>   > newLogfile

Now last 100 lines will be present in newLogfile

EDIT:

More recent versions of tail as mentioned by twalberg use command:

tail -n 100 <log file>   > newLogfile