1

Can you guys help me? I can't remember the terminal command to open a large text file, but only display (for example) 20 lines at a time. The reason for this is I am trying to read a 1.3gb error log file. Can somebody help me with the right command?

Thanks

migrated from stackoverflow.com Feb 16 '10 at 0:32

This question came from our site for professional and enthusiast programmers.

  • Hmm, how is this SO rather than SU (or SF since it's an error log)? Honestly wondering. – kb. Feb 15 '10 at 7:48
  • @kb Bash scripting == programming? :) – artemb Feb 15 '10 at 7:53
  • 1
    @artemb, it's a long-established precedent that bash scripting is programming. However, I tend to think this is more of a superuser question since it's more about how to view a file than how to write some code in bash. – paxdiablo Feb 15 '10 at 8:02
  • @artemb ah, thanks, i didn't figure that it was in a scripting context but ok, yes i guess it actually fits :D – kb. Feb 15 '10 at 11:15
8

The question heading suggests head but your body

20 lines at a time

suggests more.

5

Try man head

head -- display first lines of a file

5

head -10000 bigfile.log | tail -20 should display 20 lines around the 10000th line.

5

Try less filename.

It suits your requirement of windowing about 20 lines of a large file. A full description can be obtained with man less.

3

Try less. It displays a few lines at a time, but allows you to scroll.

less yourfilename

Read the manual for less for more info.

3

you can use head, less, more ,and awk

$ awk 'NR%20==0{print;getline <"-"}NR{print}' file

$ more -20 file

$ head -20 file # but only shows 20 lines and doesn't scroll.
  • head -20 file answers the question, more useful is more, but the awk line looks, awkward. – bbaassssiiee May 20 '14 at 5:15
0
most is the result of 20 years of fundamental research about advanced terminal paging techniques.
  • Downvoted? why ? There is a tool called "most", which was developped after "more" and "less" which is pretty awesome. – MatthieuP Mar 28 '11 at 14:04
  • Perhaps give a link? Also, don't have all of your text in code format – Roman Jan 5 '16 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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