So we use man whatever
to get usage and other info regarding the whatever
command, when the relevant section of info is found, I'd like to quit the man
command with the info left on screen. So I can type the next command with the referee above. But the man
command quits the whole screen to recover the old screen similar to vim
.
Is there a way to achieve this?
- 123
- 5
- 363
- 3
- 5
-
Related: http://serverfault.com/questions/84534/is-there-a-way-to-get-an-xterm-to-scroll-to-clear-the-screen – Jun 24 '16 at 11:59
-
All the suggestions are good, but you could also just open a second window to view the man page. And there are probably also GUI man page viewers. – Barmar Jun 28 '16 at 18:35
7 Answers
I believe this is not so much about man
itself but rather about your pager of choice (PAGER
environment variable) combined with the terminal in use.
I'm guessing your pager is probably less
(typical default pager nowadays and fits with the description).
less
has an option -X
that may get you a behavior along the lines of what you're looking for.
-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 clear‐
ing the screen.
Eg PAGER="less -X" man man
could be used for testing it out, and if you find this behavior preferable you might consider setting PAGER
to this value permanently.
- 33,741
- 5
- 65
- 90
-
-
@musiKk Works fine for me on Ubuntu 16.04 with a smart unicode terminal (not the Linux console) and man 2.7.5 – cat Jun 24 '16 at 13:24
-
3@musiKk: if you want to be able to scroll back through the man page after exiting the pager, you have to limit yourself to scrolling forward in the man page (by lines or pages), not the usual random access. – Peter Cordes Jun 24 '16 at 17:32
-
1Or you could use `LESS=-X`, to avoid having to change `PAGER` (I don't 100% trust it to work in all programs with a space like that, though it works in man.) – Random832 Jun 25 '16 at 00:23
If you are running less as your pager (which is very common), you don't need to deal with modifying your pager, just do I/O redirection:
man <whatever you want to man> | cat -
This will print a copy to the terminal so you can scroll up when you need it.
- 1,638
- 7
- 11
-
1One issue with this approach is that with long manual pages, it might be difficult to scroll back to the part of interest for you and you won't see both that part and the current command line. – jlliagre Jun 24 '16 at 10:30
-
None of the other suggestions overcome this issue - it's just inherent in a single console window. But with that said you can always write your command, scroll up a bit, and the scroll back down to your half written command. – Brennen Smith Jun 24 '16 at 18:48
-
My suggestion definitely overcome this issue. You leave the man command when the manual page that interest you is on the screen and you can type your command with that page still visible on the same screen. – jlliagre Jun 24 '16 at 21:17
-
-
-
2
-
1It's mostly for semantics - I always like to be explicit with stdin. – Brennen Smith Jun 25 '16 at 22:41
As not only less
but also other text applications like vim
exhibit the same extremely annoying feature, what I do is simply removing the ability for the terminal to support the involved commands from the terminfo
database.
These commands are smcup
and rmcup
, which were designed to allow switching on and of a move where the cup
command (cursor position) was allowed.
Here is a shell function I used to automatize the task, it works at least with Solaris and likely most Linux distributions :
fixterminfo()
{
(
[[ ! -d /tmp/terminfo ]] && { mkdir /tmp/terminfo || return ; }
cd /tmp/terminfo || return
TERM=xterm infocmp > xterm.src.org
sed -e 's/rmcup=[^,]*,//' -e 's/smcup=[^,]*,//' xterm.src.org > xterm.src
if diff xterm.src.org xterm.src
then
echo xterm terminfo already patched
return
fi
TERMINFO=/tmp/terminfo tic xterm.src
if [ -f /usr/share/lib/terminfo/x/xterm ] ; then
XTERM=/usr/share/lib/terminfo/x/xterm
else
if [ -f /lib/terminfo/x/xterm ] ; then
XTERM=/lib/terminfo/x/xterm
else
if [ -f /usr/share/terminfo/x/xterm ] ; then
XTERM=/usr/share/terminfo/x/xterm
else
echo xterm terminfo not found ; return
fi
fi
fi
if [ ! -f ${XTERM}.org ]
then
sudo cp ${XTERM} ${XTERM}.org || return
fi
cat /tmp/terminfo/x/xterm | sudo dd of=${XTERM}
)
}
If your terminal entry doesn't fallback to xterm
, you should replace xterm
by the right terminal name in the script.
- 8,691
- 16
- 36
-
1Yeah but then this breaks other programs (not necessarily pagers or curses, but readline-like editors etc) – cat Jun 24 '16 at 13:30
-
1@cat Not that I checked any existing one, but I never noticed any issues with other programs after using this workaround. Do you have examples of programs that would behave oddly ? I also suspect if they fail, that's an issue on their side. A terminal emulator is not supposed to support every terminfo capability out there. It just advertise which ones it supports and it is up to the application to deal with it. – jlliagre Jun 24 '16 at 14:32
You can pipe the output to the cat
command
man man|cat
or use it instead of the default pager, as in this example which invoke man on itself:
PAGER=cat man man
- 382
- 1
- 4
Without modifying the pager, a solution with pipes that can work in most of the environments:
Examples for man ls
- Leave the entire man page in the screen
man ls | cat
- Read a paginated man output, with the possibility of leaving it any time with q:
man ls | more
- filter man contents with a pattern and keep matching lines in the screen:
man ls | grep somestring
- 248
- 1
- 3
- 11
it's 2016, just open a second terminal or tab or window or read the man online ..
-
-
1@Braiam Not practical if the terminal is on mobile phone screen. – NathaneilCapital Jun 25 '16 at 04:46
-
Even on my servers (FreeBSD) I install X and xfce. Then I allocate a big buffer (e.g. 10 000 lines) for the terminal emulators so that I can fully scroll out the man page in one of them, and use a separate terminal instance to assemble the command. Works a treat.
- 141
- 1
- 6