Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Relatively often, I find myself wanting to quit less but leave what I was viewing on the screen, to refer back to. Is there any way to do this? Workarounds?

(My current workaround is to quit, then use more. So any workaround that's better than that is welcomed. The ideal would be something I can use once I'm already inside less, perhaps with a shell setting or some scripting.)

My desktop is OSX, but I use RHEL and Ubuntu servers.

share|improve this question
Reading a long output (as in git diff or git log) in less -X will take up the scroll buffer in my terminal and evict much of the previous output. I'd love it if less could just exit with the last screenful of output at the time of the exit; i.e. no more than one page of the scroll buffer would be taken after quitting less. Any ideas? – musiphil Jan 9 '14 at 19:57
By the way, -R is usually a safer choice than -r. – musiphil Jan 9 '14 at 20:14
Thanks. For those wondering: -R is "Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained correctly in most cases." – Steve Bennett Jan 13 '14 at 4:20
@musiphil Perhaps -c? – Matthew Phipps May 1 '14 at 16:46
Thanks for the useful question! – Dr Beco Feb 8 at 0:36
up vote 47 down vote accepted

This is actually a function of the terminal emulator you are using (xterm, gnome-terminal, konsole, screen). An alternate screen, or altscreen, gets launched when programs such as less or vim are invoked. This altscreen has no history buffer and exits immediately when you quit the program, switching back to the original screen which restores the previous window content history and placement.

You can prevent less from launch in an altscreen by passing the argument "-X".

less -X /path/to/some/file

You can also pass "-X" as an environment variable. So if you are using bash, place this in ~/.bashrc:

export LESS="-X"

However, this disbles the termcap (terminal capability) initialization and deinitialization, so other views when you use less may appear off.

Another option would be to use screen and set the option altscreen off in your ~/.screenrc. less will not clear the screen and should preserve color formatting. Presumably tmux will have the same option.

This blog entry describes the problem and offers some different solutions specific to gnome-terminal with varying success.

share|improve this answer
Perfect. Is there a downside? – Steve Bennett May 14 '12 at 13:46
@SteveBennett Not that I'm aware of. – uther May 14 '12 at 13:47
@SteveBennett That's small enough I'd make it an alias: alias les="/usr/bin/less -X" – bonsaiviking May 14 '12 at 14:33
Hey, I think I just discovered an antidote to the git log issue above: export LESS="-r -X". (No idea what the side-effects of that are...) – Steve Bennett May 14 '12 at 14:43
Actually, git sets the LESS variable to FRSX if it is unset when it runs the pager, so you can just leave LESS unset and less will automatically run with -FRSX. Look for core.pager in git-config(1) for more information. – musiphil Jan 9 '14 at 19:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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