How to escape out of the MAN screen or page in UNIX?
Solution 1
The man
command uses your default pager, which is specified by $MANPAGER
if it's set, or by $PAGER
. If neither is set, it defaults to something reasonable, probably either more
or less
. (Oddly, I don't see this in the man page for the man
command, which you can view by typing man man
-- once you get back to your shell prompt.)
Most pagers can be exited by typing q -- which is going to be a useful thing to know for other programs that invoke your pager, or when you use your pager directly to view a file (less some-file.txt
).
When I run the man
command on my system, the bottom line shows:
Manual page ls(1) line 1 (press h for help or q to quit)
in reverse video. Do you see that? (You may or may not, depending on your settings.)
If your pager is less
, then you can get more information by typing h for help -- or by typing man less
.
Solution 2
You can press the q key to exit the man pages.
FYI:
In my experience, the man
generally uses less
to display the information. To get a helpful list of keyboard shortcuts (navigation, exiting) for less
(and for man
), you can type in:
less --help
Here is a brief exerpt:
SUMMARY OF LESS COMMANDS
Commands marked with * may be preceded by a number, N.
Notes in parentheses indicate the behavior if N is given.
h H Display this help.
q :q Q :Q ZZ Exit.
---------------------------------------------------------------------------
MOVING
e ^E j ^N CR * Forward one line (or N lines).
y ^Y k ^K ^P * Backward one line (or N lines).
f ^F ^V SPACE * Forward one window (or N lines).
b ^B ESC-v * Backward one window (or N lines).
z * Forward one window (and set window to N).
w * Backward one window (and set window to N).
ESC-SPACE * Forward one window, but don't stop at end-of-file.
d ^D * Forward one half-window (and set half-window to N).
u ^U * Backward one half-window (and set half-window to N).
ESC-) RightArrow * Left one half screen width (or N positions).
ESC-( LeftArrow * Right one half screen width (or N positions).
F Forward forever; like "tail -f".
r ^R ^L Repaint screen.
R Repaint screen, discarding buffered input.
---------------------------------------------------
Default "window" is the screen height.
Default "half-window" is half of the screen height.
Related videos on Youtube
bashboy
Updated on September 15, 2022Comments
-
bashboy over 1 year
I entered
man ls
. This shows a screen with the manual for ls. I want to close this manual and go back to the previous screen. How do I do it ? The man page for ls is not allowing me to do so. It keeps on showing "(END)" or some message when I try to type a unix command.I am a newbie so please don't downvote me.
-
bashboy almost 11 yearsHow did you come to know that ? Is it mentioned somewhere in a man page ?
-
bashboy almost 11 yearsHi ! I have some questions. What is a pager ? You said that most pagers can be exited by q. Is there any other key to exit the unusual pagers ? Also, is there a way to change exit key from q to "zzz" or esc key ?
-
bashboy almost 11 yearsI don't see - Manual page ls(1) line 1 (press h for help or q to quit). Also, I am not able to copy the entire text of man page. I was thinking of searching your line after copying the text onto windows word.
-
Keith Thompson almost 11 years@bashboy: A pager is a program that lets you view a text file. Older ones could only show a file one page at a time, thus the name; modern pagers let you scroll a line or half-page at a time, and to go forward and backward.
less
is configurable;man less
for details. But you might consider just sticking with the defaults until you're more familiar with the system. -
user1934428 almost 2 years@KeithThompson : My cygwin man-page for man states for the case of neither MANPAGER nor PAGER being set: By default, less is used, falling back to cat if less is not found or is not executable.
-
user1934428 almost 2 years@bashboy : If you want to experiment with warious pagers, before setting it as environment variable, you can use the option
-P
to specify your own pager, for instance to show the man-page for ls using the most-pager, you could try this with ` man -P most ls` (provided, of course, thatmost
is in your PATH).