Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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? – freethinker May 20 '11 at 7:16
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 '11 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 – LanceBaynes May 20 '11 at 7:47
up vote 2 down vote accepted

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)

share|improve this answer
I'd also recommend view, if you are familiar with vi. – jmtd May 20 '11 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
share|improve this answer

Your Answer


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.