0

For example, if I view a piece of doc called a.txt in linux. Here is my prompt:

user $ less a.txt
This is a document named a.txt, here is what happened when I press 'q'
user $ 

Small document doesn't bother me, but when i just looked through a code of 2000 lines length, I couldn't see anything from my previous commands other than looking into $history.

How do I stop display doc/code upon exist ('q')?

return 0
  • 195

2 Answers2

1

Normally the behaviour you ask for is the default. Commands like less use a feature called altscreen to write to a different buffer whilst they run. On exit the previous screen is restored, and none of the less output is visible.

This feature depends on what terminal emulator you are using (xterm, dtterm, ...) and how you set the TERM environment variable in the shell. Try echo $TERM to check it is not dumb for example.

meuh
  • 6,624
0

As said what you are asking is the normal behavior that is expected. The screen does not get cleared if you run less specifically with the -X flag like this :

less -X filename

you could specifically check for the following :

1) If any aliases are set where you see less is set to less -X . Just run the command alias

2) Check for the env variable LESS if its set to -XF like this and unset it :

[root@host]# env | grep LESS

LESS=-XF

3) Check for an env variable and unset it if it exists PAGER='less -X'

Read more here(though it is to switch it off ) :

'less' command clearing screen upon exit - how to switch it off?