Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

Can I get the specified number lines at a time by using the less command? I want just ex. show 20 lines even if my screen allows more.

share|improve this question

closed as unclear what you're asking by Anthon, slm, jasonwryan, Alexios, terdon Dec 19 '13 at 16:54

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

when less it started the line numbers displayed, and the total number of lines is reported at bottom of screen. – suspectus Dec 19 '13 at 12:53
Please explain exactly what you are trying to do, it does not seem like less is the correct tool for the job. – coteyr Dec 19 '13 at 13:02
ls | head 40 | tail 10 will show entries 31-40, but maybe I don't understand what you mean. – coteyr Dec 19 '13 at 13:12
@Anthon I am not new SE. I am here from almost 2 years. Thank you. & by the way I am giving votes also. – Raja Dec 19 '13 at 13:14
If you think it is worth 20 downvotes, either fix the question or delete it. – jasonwryan Dec 19 '13 at 16:20
up vote 3 down vote accepted

less works with screens of text. The "screen" is the full size of the terminal.

less --window=n can tell less to only use so many rows at a time. That being said the option is not always available.

see man less

If you only want "some" output try tail -n 20 /file.txt for the last 20 lines, or I personally use head -n 20 | tail -n 10 to get the middle 10 lines.

share|improve this answer
I am sure there is a way to tell the terminal to only be so many rows, but that seems like a lot of work. – coteyr Dec 19 '13 at 13:01

Display a file from line number X:

less +X filename

Use the -N option to output line numbers

e.g less +15000 -N filename

displays from line number 15000 with line numbers displayed

share|improve this answer
thank you , how about output from terminal & not from a file ? can i still use this ? – Raja Dec 19 '13 at 13:05
yes works fine from a terminal. e.g. cat filename | less +15000 -N – suspectus Dec 19 '13 at 13:07
terminal output from some commands. Not from a file. – Raja Dec 19 '13 at 13:10
yes the same principle applies ps | less +2 – suspectus Dec 19 '13 at 13:13

from less manual, to scroll n lines at a time, but shows a whole screen-full.

-[z]n or --window=n

Changes the default scrolling window size to n lines. The default is one screenful. The z and w commands can also be used to change the window size. The "z" may be omitted for compatibility with some versions of more. If the number n is negative, it indicates n lines less than the current screen size. For example, if the screen is 24 lines, -z-4 sets the scrolling window to 20 lines. If the screen is resized to 40 lines, the scrolling window automatically changes to 36 lines.

share|improve this answer

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