How to make ‘man’ or ‘less’ paged text not disappear from screen after exit?


Depending on your Linux distribution, the text displayed by the ‘man’ command  (or any other text piped into ‘less’ for that matter) may stay on your screen upon exit from man/less or be cleared from your screen upon exit. Many people find it useful to have the man page text stay on the screen, such that you could, for example, read it once more while constructing your regular expression. If you’re one of them folks having this problem here’s how you can make the text displayed by man or less not be removed from your terminal screen when you exit from man or less.

The “root of problem” is with the ‘less’ program, which ‘man’ uses to display its pages. And it is not really a “problem”, as in a bug, but just the way less is invoked on the various Linux distributions.  In order to have the paged text stay on the screen after exit less must be invoked with the -X option:

# less -X

Ok, that was easy, so from now on you could always call less with the -X switch and the text will not be removed from the screen! Even better – add an alias to your .bashrc file and you will not need to type the -X each time you invoke less, the alias will tell it to always run with  the -X option. To do this open in an editor the file .bashrc in your user home directory and add this line to the end:

alias less='less -X

Ok so that solved our problem with less but what about man? Maybe it will also pick-up the alias settings that we put into the .bashrc? A quick test with a newly opened bash session shows that unfortunately it does not…  🙁

Instead, in order to make the man pages also not disappear from the screen on exit we can use the MANPAGER env variable, which man looks into to see which program to use to display the man pages!

# export MANPAGER="less -X"

# man fopen

To make these settings permanent (like we did with the ‘less’ allias) append the above  export line to your .bash_profile file, which is also located in your home directory… (Note that this time we are modifying the .bash_profile file, not .bashrc!)


6 thoughts on “How to make ‘man’ or ‘less’ paged text not disappear from screen after exit?

  1. oh, I didn’t know one MUST have a facebook profile nowadays… Hope I didn’t break any laws? …guess I’ll better go make myself one before it’s too late…

    Sorry to disappoint you my friend, but I try to stay away from this CIA-controlled monstrosity, called facebook. 🙂

  2. The MANPAGER trick worked on Fedora but not on Ubuntu… AFter some searching on the web this solved the problem:

    export LESS="-X"

  3. Hi there! I simply would like to offer you a big thumbs
    up for the great info you’ve got here on this post. I’ll be coming back to your web site for more soon.

  4. This design is wicked! You most certainly know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to
    start my own blog (well, almost…HaHa!) Excellent job.
    I really loved what you had to say, and more than that, how you presented it.

    Too cool!

Leave a Reply

Your email address will not be published. Required fields are marked *