This question already has an answer here:

I have a question just opposite to Is there any way to exit "less" without clearing the screen?: my less exits without clearing the screen but I have never used -X.

The options I use is as follows:

$ echo $LESS 
-N -g -i -M -R -w -z-4
$ echo $LESSOPEN
$ echo $TERM

I remember when my less have started to change its behavior is when I was trying to typing something to another application but my cursor was in the terminal with less opening. When I realized I am typing into a wrong place and tried to quit the my less, the file contents start to remaining to my terminal. I am using mac OS terminal (not iTerm2).

Thanks in advance.

[Edit] Thanks for the suggesting of existing posts. As @roaima suggested, my issue is to get the less's standard behavior without -X. However, -+X does not works, neither -X is in LESS.

[Edit 2] I am using OSX Terminal.app, not iTerm2

marked as duplicate by G-Man, roaima, Thomas Dickey, Jeff Schaller, Romeo Ninov Aug 17 '18 at 17:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


If you really want less to clear the screen when it exits you can redefine the command like this

less() { command less "$@"; clear; }

On the other hand, if you want less to save the original content of the screen and restore that when it exits, this should be standard behaviour. (It's managed through the ti and te entries of TERMINFO and/or TERMCAP. These are set according to the terminal type as evidenced with echo $TERM.)

You can try forcing off the -X option with

less -+X

But if that doesn't work either, provide the result of running an echo $TERM command, and it should be possible to determine what the ti and te values are, and therefore why they're not saving and restoring the screen.

  • Thank you @roaima, My issue is to get standard behavior, but less -+X does not work. $ echo $TERM returns ansi – paracosmo Aug 20 '18 at 2:08
  • Have you read the answer I've highlighted in the duplicate? – roaima Aug 20 '18 at 6:32
  • Yes, but I'm not using iTerm2. I'm having this issue in the OSX Terminal.app and I can't find anything similar to "Save lines to scrollback in alternate screen mode" in its preference... Or did I missed something? – paracosmo Aug 21 '18 at 7:34
  • 1
    Yes! You're not updating your question with this information you gradually disclose. People can't know what you don't tell them. – roaima Aug 21 '18 at 7:56

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