5

Beginners question:

I am reading a man page called in a ssh (putty) session, i.e:

man usermod

Now this man page has about 252 line, when reaching the end, I press q for quit. It would be very helpful if all the lines from man page would remain in the terminal window for scrolling, but it will be cropped, only last 50 lines stays in terminal window.

Probably very simple, but did not find a similar question.

3
  • Is this question really related to putty and bash? I also wonder if you tried man man. It's also unclear what the actual question is: Assuming that today's UNIX uses less for paging: Did you try b to go back one page, or k to go back one line (or h for help)?
    – U. Windl
    Aug 16, 2023 at 9:14
  • yes, I tried h for help. When issueing man usermod I can use bor k for navigating inside the page, but that wasn't the question. The whole content of the man page should retain in the window for further reading. The answer of @Vilinkameni helped me finding a solution for that. Now I know that a pager is involved when using man and that I can also select between different types of these pagers while viewing man pages. Should I remove the tags bash and putty? I thought it could be helpful for others.
    – MMAX
    Aug 17, 2023 at 8:47
  • I think it's basically a "man" question. I also think scrolling using a pager is preferable over using a terminal emulator to scroll; mostly because you can search in the pager. Finally let me remark that I started using UNIX on a 9600 baud serial terminal with no scrollback, and as the pager was more or pg (not less), you could not go back at all...
    – U. Windl
    Aug 17, 2023 at 10:20

5 Answers 5

4

From man man:

     MANPAGER  Any non-empty value of the environment variable MANPAGER is
               used instead of the standard pagination program, less(1). 

So, you would invoke man as such:

MANPAGER=cat man usermod

Alternatively, you can pipe through cat to disable paging:

man usermod | cat

Note: Some versions of man support the use of -c parameter, which does the same:

man -c usermod

Consult man(1) to confirm if your system supports it.

3
  • Debian 12 does not have this -c parameter in man. But the alternative with piping into cat is sufficient enough for me, thx a lot for this.
    – MMAX
    Aug 15, 2023 at 10:45
  • @A.B that's more to do with ti/te and the alternate screen, isn't it? In which case less -X will be appropriate. Or have I misunderstood you Aug 15, 2023 at 20:25
  • @roaima (and after having fixed my typo when testing) yes MANPAGER='less -X' man man gets the behavior OP wants too.
    – A.B
    Aug 15, 2023 at 22:38
4

Don't quit the pager (q) until you have finished reading the documentation.

While you're still in the pager you can scroll up and down. For example, using less as the pager the corresponding keys are b, , Page Up to scroll up/backwards, and Space, , Page Down to scroll down/forwards.

2
  • 1
    man less is also helpful, in particular using / to search. Still, OP's question was about using the features of the terminal emulator to browse the manpage instead. Aug 15, 2023 at 18:04
  • @Vilinkameni if you said you needed to fix a screw into wood but all you had was a hammer, I would still advise you to use a screwdriver (or a nail). Similarly, for browsing a manpage I believe that using a pager is more effective solution than to scroll a terminal (what if the terminal scrollback buffer is too small for the manpage, for example). The OP says they are a beginner so it is possible they don't know it's possible to scroll upwards/backwards using a pager Aug 15, 2023 at 18:10
2

Add export MANPAGER="less -X" to your ~/.bashrc and use only man usermod in your next bash session to keep less' output.

1
  • I think this will leave something in the terminal scrollback buffer, but it won't be a copy of the manpage (maybe unless you just scroll through it from start to stop and then quit.) It will just be whatever happens to be there when less quits. That might be good enough, depending. Aug 16, 2023 at 4:34
1

In other answers, advice is given for

  • substituting cat for less to avoid whatever unspecified limitations the latter may have,
  • staying in less to keep access to the content which works around the problem,
  • using the -X option of less without mentioning why this addresses the issue, and
  • using putty's option (in the Window dialog) to change the length of the scrollback.

However, on a different dialog (Terminal / Feature), putty allows one to suppress switching to the alternate screen. If those two features are combined, then putty will not switch to to the alternate screen when displaying the file (and on completion and quitting the pager as specified by OP) will not clear the screen, leaving the whole content available for scrolling using putty's built-in handling up page-up/page-down.

The -X option of less does something like that Terminal / Feature option:

       -X or --no-init
              Disables sending the termcap initialization and
              deinitialization strings to the terminal.  This is
              sometimes desirable if the deinitialization string does
              something unnecessary, like clearing the screen.

but does not address putty's limit on the number of lines retained on the window. OP may have chosen (or relied upon) a modified terminal description which omits smcup / rmcup (the terminfo capabilities that less ends up using), but did not mention this. Telling putty to do this resolves the ambiguity.

putty (like most of the terminal programs you would use) implements xterm's alternate screen feature. It is one of the (relatively few) to provide a way to suppress it at runtime: most simply hardcode the behavior as the original xterm did. Because of this prevalence of hardcoding, in a few cases, packagers have modified the terminal description to omit the feature, though preference for the feature appears to be equally split.

1
  • 1
    After reading all the advices here, I now understand that the default pager for displaying man pages in the debian I am running (12.1) is less, already. And with the option -X the expected behaviour can be achieved, too. But in the post above, the explanation to this -X option should be related to less and not putty?
    – MMAX
    Aug 17, 2023 at 9:19
0

Using the pager mentioned in the other answers is what you can and should do.

However, to answer the question as asked: you can set up scrollback buffer size in PuTTY under Settings / Window / Lines of scrollback:

enter image description here

Note that it will help you only if you are not using less as a pager (the default on most systems these days): it will redraw the screen instead of scrolling.

2
  • You missed a detail in Terminal/Features which could improve your answer. Aug 15, 2023 at 22:38
  • 1
    @ThomasDickey In that case, why don't you tell what the detail is in your comment? Aug 16, 2023 at 6:08

You must log in to answer this question.

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