[SOLVED] How can I preserve screen on exit from 'man' or 'less'?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I preserve screen on exit from 'man' or 'less'?
Hello,
Alright linuxquestions.org website, you've noted nearly 1000 times that I've never posted a question, and that I'm missing out on all the wonderful benefits thereto appertaining. So here goes:
On SunOS, Solaris, AIX, (most any *nix save for Linux pretty much), when I <ctrl/c> out of a 'man' page or quit out of 'less', whatever I was looking at STAYS DISPLAYED ON THE TERMINAL WINDOW and I get a command prompt at the bottom of the terminal. This is great, because what is displaying on the screen is typically the option/switch/syntax/ whatever answer I've been looking for, and have now found, and I am now perfectly and conveniently positioned to use that answer in whatever program/command/utility that I was trying to run.
Except in Linux.
In Linux my long-sought-and-finally-found new knowledge and intelligence VANISHES as soon as I exit the 'man' or 'less' command. I had it, right there!! I was all set to USE IT at the command prompt!! But now I can't, BECAUSE IT IS GONE!!!
Why is this?? What is the advantage to that?? And please, unless you are going to buy me more monitor real estate DON'T TELL ME TO OPEN UP ANOTHER TERMINAL WINDOW! I KNOW I CAN OPEN UP ANOTHER TERMINAL WINDOW. I CAN BUY ANOTHER COMPUTER AND SET IT UP NEXT TO THE ONE I AM USING, TOO, BUT BOTH IDEAS SEEM STUPID TO ME.
Perhaps it's because it annoys me as much as it obviously does, or perhaps it's because whenever I encounter this PITA I am in the midst of dealing with some other PITA that has driven me to consult man pages or other documentation in the 1st place, but I have a difficult time calmly seeking solutions to this problem. I don't even know wherein it lies, really. Is this behavior determined by stty settings or termio characteristics? Is it actually built into the 'man', 'less', and other executables, or some library that they call? Or is it determined someplace else?
Has anyone already doen something about this annoyance? Has anyone fixed 'man' and 'less', or resolved it in some other way?
Anyhow, I asked my question. So, ummm, what about all these great bennies??
Don't forget to source your ~/.bashrc after editing
Code:
source ~/.bashrc
I'll add this to .bashrc eventually, but for now I enjoy typing it at the command line! This is as useful an addition to my understanding of 'less' (and therefore to the man manuals in Linux, I guess) as is typing "-N" to toggle the line number display.
I never knew there was an environment variable for less. It looks like it's the 'X' part that fixes the problem, by suppressing certain terminal commands on exit. I suppose further research into that, and why it differs for different Unixes, is now someplace in my to-do pile.
I'll add this to .bashrc eventually, but for now I enjoy typing it at the command line! This is as useful an addition to my understanding of 'less' (and therefore to the man manuals in Linux, I guess) as is typing "-N" to toggle the line number display.
I never knew there was an environment variable for less. It looks like it's the 'X' part that fixes the problem, by suppressing certain terminal commands on exit. I suppose further research into that, and why it differs for different Unixes, is now someplace in my to-do pile.
Again, thank you!
The fun part is, while ranting about the behavior of man and less you seem to not have checked the man-page of less, where the environment variable is extensively described, with all options. It is indeed the X part that causes the wanted behavior:
Code:
-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.
Tip for the future: Writing in all caps and using oversized fonts counts as yelling and is considered to be rude on most forums. This may deter members of LQ from actually helping you.
I'll add this to .bashrc eventually, but for now I enjoy typing it at the command line! This is as useful an addition to my understanding of 'less' (and therefore to the man manuals in Linux, I guess) as is typing "-N" to toggle the line number display.
I never knew there was an environment variable for less. It looks like it's the 'X' part that fixes the problem, by suppressing certain terminal commands on exit. I suppose further research into that, and why it differs for different Unixes, is now someplace in my to-do pile.
Again, thank you!
You're welcome.
NOTE: I use a reload alias in my .bashrc explicitly for this purpose
Code:
alias reload='clear && source ~/.bashrc'
"clear &&" is optional, but I prefer to have a clean screen.
The fun part is, while ranting about the behavior of man and less you seem to not have checked the man-page of less....
It's only recently that I realized it was necessary to check out 'less' at all. In other Unixes I've used 'less' is not the pager employed by the 'man' facility.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by Clovis_Sangrail
On SunOS, Solaris, AIX, (most any *nix save for Linux pretty much), when I <ctrl/c> out of a 'man' page or quit out of 'less', whatever I was looking at STAYS DISPLAYED ON THE TERMINAL WINDOW and I get a command prompt at the bottom of the terminal. This is great, because what is displaying on the screen is typically the option/switch/syntax/ whatever answer I've been looking for, and have now found, and I am now perfectly and conveniently positioned to use that answer in whatever program/command/utility that I was trying to run.
Except in Linux.
Not sure about the other OS mentioned but ironically, the Solaris behavior you describe was not a feature but a bug that was fixed in the last release (Solaris 11).
Instead of using hard to remember extra options or settings, a more radical way is simply to remove the alternate screen abomination (rmcup/smcup) from the terminfo entry your terminal emulator uses.
I'm doing that to every Unix/Linux machine I own/administrate.
... a more radical way is simply to remove the alternate screen abomination (rmcup/smcup) from the terminfo entry ....
When I encounter the portions of *nix that predate the Internet, I begin to feel less like a SysAdmin and more like an Archeologist. Terminfo, ttydb, tip, cu, ... these are all things from an earlier time and I know much less of them than the more modern parts of Unix. Do you have an overall sense of how much xterm, dtterm, and other GUI/Internet emulations of tools from the teletype/serial-terminal era interface with and make use of facilities like terminfo and follow their conventions, and how much they ignore the old tools, possibly 're-inventing the wheel' so to speak?
When I encounter the portions of *nix that predate the Internet, I begin to feel less like a SysAdmin and more like an Archeologist. Terminfo, ttydb, tip, cu, ... these are all things from an earlier time and I know much less of them than the more modern parts of Unix.
Well put, friend. Termcap, too. I still run into things that use that.
VT100 emulation? All the variations on which ANSI escape sequences can make the cursor go to the beginnning or end of the line? Whether you use xterm, rxvt, gnome-terminal, etc, and which ones do they obey, and which ones did they invent to support transparency and right-to-left fonts? Line drawing characters and alternate character sets. Console codes. The list goes on...
Instead of using hard to remember extra options or settings, a more radical way is simply to remove the alternate screen abomination (rmcup/smcup) from the terminfo entry your terminal emulator uses.
I'm doing that to every Unix/Linux machine I own/administrate.
See, that makes you clever. You even *knew* the appropriate abominations to delete Deep Voodoo.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
There are not that much applications using termcap on Linux. Some of the ones that needs to format their output are based on ncurses. This include elvis, htop, nano, pico, watch. Most of them are however directly using terminfo like pico, pstree, screen, top, vim ...
Back to the topic, another similar abomination that I always remove from the accounts I use is the default .bash_logout script that clears the screen at logout.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.