'less' doesn't clear screen after quit


The default behavior for 'less' is to clear the screen after quitting. This behavior stopped when I started using:

export TERM=xterm

Now 'less' leaves the last page I viewed on the screen, and I want to re-enable the default behavior of clearing the screen.

Googling this problem I found that people use the following command in their ~/.screenrc:

altscreen on

I'm not sure if this is a mac-issue but I don't have this command available.

I'm using bash shell on Mac terminal and I have no $LESS environment variable defined.


Posted 2011-06-30T14:30:01.320

Reputation: 121

1This isn't a duplicate. The other question explicitly asks about the problem inside GNU screen. This one has nothing to do with screen, as evidenced by, "I don't have [altscreen] available" and "I'm using bash shell on Mac terminal." – peth – 2011-06-30T19:02:16.827

What happens when you call less like: less -+F -+X <file>? If that changes the behavior, your less is configured to behave that way somewhere in you system configuration. If not, it's likely that your terminal doesn't support the alternate screen feature or doesn't have it enabled. You'd need the reverse of http://superuser.com/questions/136162/how-can-i-still-see-the-man-text-after-i-quit-man/136205#136205 or get a terminal that has the alternate screen feature.

– peth – 2011-06-30T19:11:39.477

@peth: This really isn't a duplicate question. As for your question, no matter how I play with the command line options, the last page always remains on the screen. I don't think this has something to do with the less configuration since this only started happening after I defined export TERM=xterm. Thanks for your help! – Dana – 2011-07-01T16:02:06.920



Take a look at your $LESS environment variable and make sure it doesn't specify -X. I specifically add this to $LESS, because I don't want the screen cleared. Here is a snipet from the manpage:

-X or --no-init Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deini- tialization string does something unnecessary, like clearing the screen.


Posted 2011-06-30T14:30:01.320

Reputation: 8 506

I have no $LESS environment variable defined at all – Dana – 2011-06-30T17:20:28.157

As mentioned in the question, this only started happening after I defined export TERM=xterm, so I believe this is not a problem of less definitions. – Dana – 2011-07-03T22:50:59.030


This answer is an extension to the answer by @KeithB.

check the options of LESS by echo $LESS. If it has option -X, remove it.

LESS="options"; export LESS

In options include options other than -X. More information, check the manpage.


Posted 2011-06-30T14:30:01.320

Reputation: 101


Some clarification is needed: less will only clear the screen as a part of displaying a new page. What is described in the question is the alternate screen, an xterm feature that Terminal.app supports.

When you see the screen cleared, that is because the terminal has switched to the alternate screen temporarily (to run less) and has switched back to the normal screen (showing just your shell prompt and whatever preceded that before running less).

less gets the information on how to switch to/from the alternate screen from the terminal description, using $TERM to find this information. I don't see this in OSX now (the question dates from 2011), but some developers dislike the feature and remove it from the terminal description (for example, FreeBSD).

The question did not say what $TERM was before changing it to xterm. That used a different terminal description, where the feature had not been removed.

Thomas Dickey

Posted 2011-06-30T14:30:01.320

Reputation: 6 891