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

Today I was using glance tool in my office to monitor CPU utilization.When I run glance from terminal ,the command clears the screen and after all the work when I quit back to the terminal,the previous prompts are still there on my screen.I mean that I can see all the previous lines.My question is how is this effect of clearing screen achieved.If they had used command like clear,It should have cleared the whole screen,how did they manage to get back all the previous prompts ? I want to implement the same feature for some of my scripts.

Similarly when using vi command ,the screen is fully occupied and after exiting,we are able to view previous prompts as well.

share|improve this question
Apps like that use a terminal interface library such as ncurses. When it ends, you return to the shell where you were. – goldilocks Mar 12 '13 at 16:32
up vote 3 down vote accepted

Many terminal emulators maintain two copies of the terminal output: the normal screen buffer, and the alternate screen buffer. The normal buffer is for command line applications which normally don't move the cursor outside the current line and provides scrollback. The alternate buffer is for full-screen applications and does not provide scrollback.

Glance, vi and others switch to the alternate screen when they start and switch back when they exit.

In xterm, you can see the non-current screen by toggling “Show Alternate Screen” in the middle mouse button menu.

From a script, you can obtain the control sequence to switch between screens with tput smcup and tput rmcup (smcup and rmcup are the terminfo capabilities to switch into and out of full screen mode).

share|improve this answer
@Giles: Hi,Can you please have a look at this question ? unix.stackexchange.com/questions/67877/screen-buffer-and-dialog – g4ur4v Mar 14 '13 at 7:41

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.