Are there any better solution to this?

tail -200 /var/log/messages | head -100

Are there other methods to achieve this output? (not more complex, I'm looking for simpler solutions!)

  • just wondering, why would you want to look at the lines 200 to lines 100 (from the bottom) and not the last 100 lines, or is the intention to check 100 lines at a time? May 20, 2011 at 7:16
  • 1
    This is simple enough as it is. If that is a small part of a bigger task, you may need to describe and ask about that.
    – forcefsck
    May 20, 2011 at 7:33
  • actually firstly I used tail -1000 so I read the last 1000 lines, but I needed more to read, and I don't wanted to scroll the last 1000 May 20, 2011 at 7:47

2 Answers 2


If you want to browse through a file interactively, just use less log. You can exit less via q, h is the help screen. Example session:


(which means: jump to the end, move 1000 lines up, 100 lines down, one screen forward and one screen backward)

  • I'd also recommend view, if you are familiar with vi.
    – jmtd
    May 20, 2011 at 12:31

If you know the starting line number (counted from the beginning of the file), you can use sed like this to output the above lines intervall:

$ for i in `seq 500`; do echo $i; done > t
$ sed -n '300,400p' t

(which prints the lines 300 until 400)

If you don't know the start line (address in sed lingo), you can reverse the input, use sed and reverese again:

$ tac t | sed -n '101,201p' | tac

You can also use sed with a start address and specify how many following lines should be printed:

$ tac t | sed -n '101,+100p' | tac

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .