How to force the less program to not clear the screen upon exit?

I'd like it to behave like git log command:

  • it leaves the recently seen page on screen upon exiting
  • it does not exit the less even if the content fits on one screen (try git log -1)

Any ideas? I haven't found any suitable less options nor env variables in a manual, I suspect it's set via some env variable though.

  • Presumably you need the scrolling aspect of less, so more would not be suitable? – Svend Feb 9 '10 at 11:48

To prevent less from clearing the screen upon exit, use -X.

From the manpage:

-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.

As to less exiting if the content fits on one screen, that's option -F:

-F or --quit-if-one-screen

Causes less to automatically exit if the entire file can be displayed on the first screen.

-F is not the default though, so it's likely preset somewhere for you. Check the env var LESS.

  • Excellent! -X is what I had in mind. – Wojciech Kaczmarek Feb 10 '10 at 14:31
  • 7
    This is especially annoying if you know about -F but not -X, as then moving to a system that resets the screen on init will make short files simply not appear, for no apparent reason. This bit me with ack when I tried to take my ACK_PAGER='less -RF' setting to the Mac. Thanks a bunch! – markpasc Oct 11 '10 at 3:44
  • @markpasc: Thanks for pointing that out. I would not have realized that this combination would cause this effect, but now it's obvious. – sleske Oct 11 '10 at 8:45
  • 7
    This is especially useful for the man pager, so that man pages do not disappear as soon as you quit less with the 'q' key. That is, you scroll to the position in a man page that you are interested in only for it to disappear when you quit the less pager in order to use the info. So, I added: export MANPAGER='less -s -X -F' to my .bashrc to keep man page info up on the screen when I quit less, so that I can actually use it instead of having to memorize it. – Michael Goldshteyn May 30 '13 at 19:28
  • 2
    It kinda sucks that you have to decide when you start less how it must behave when you're going to exit. – Michael Burr Mar 18 '14 at 22:00

If you want any of the command-line options to always be default, you can add to your .profile or .bashrc the LESS environment variable. For example:

export LESS="-XF"

will always apply -X -F whenever less is run from that login session.

Sometimes commands are aliased (even by default in certain distributions). To check for this, type


without arguments to see if it got aliased with options that you don't want. To run the actual command in your $PATH instead of an alias, just preface it with a back-slash :


To see if a LESS environment variable is set in your environment and affecting behavior:

echo $LESS
  • 2
    In fact, I add export LESS="-XFR" so that the colors show through less as well. – dotancohen Sep 2 '14 at 10:12
  • 2
    Thanks for that! -XF on its own was breaking the output of git diff, and -XFR gets the best of both worlds -- no screen-clearing, but coloured git diff output. – Giles Thomas Jun 10 '15 at 12:23

Or just set it in your global git config:

git config --global core.pager 'less -FX'

This way other tools are unaffected (which I like).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.