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

When starting XTerm the prompt starts at the first line of the terminal. When running commands the prompt moves down until it reaches the bottom, and from then on it stays there (not even Shift-Page Down or the mouse can change this). Rather than have the start of the terminal lifetime be "special" the prompt should always be at the bottom of the terminal. Please note that I have a multi-line prompt.

Of course, it should otherwise work as before (resizeable, scrollable, no unnecessary newlines in the output, and no output mysteriously disappearing), so PROMPT_COMMAND='echo;echo;...' or similar is not an option. The solution ideally should not be shell-specific.

Edit: The current solution, while working in simple cases, has a few issues:

  • It's Bash specific. An ideal solution should be portable to other shells.
  • It fails if other processes modify PS1. One example is virtualenv, which adds (virtualenv) at the start of PS1, which then always disappears just above the fold.
  • Ctrl-l now removes the last page of history.

Is there a way to avoid these issues, short of forking XTerm?

share|improve this question
Somehow, we need to introduce blank characters in Xterm's scrollbar buffer. – SHW Sep 1 '14 at 8:31
Actually, the prompt can be easily moved back to the top at any time by executing clear command. – werediver Sep 1 '14 at 8:49
@SHW I was hoping there was a setting for this rather than a hack. Terminal hacks have a tendency to introduce very subtle bugs in my experience. – l0b0 Sep 1 '14 at 11:37
@werediver But I never want it to be on top. – l0b0 Sep 1 '14 at 11:38
Since only the shell knows when it outputs a prompt, any solution must be in the context of the shell. Even forking XTerm won't help because XTerm doesn't know whether what it is asked to output is a prompt or not. For the terminal, the shell prompt is just another character sequence, no different from any other character sequence it might receive. – celtschk Sep 12 '14 at 15:13

If using bash, the following should do the trick:

TOLASTLINE=$(tput cup "$LINES")

Or (less efficient as it runs one tput command before each prompt, but works after the terminal window has been resized):

PS1='\[$(tput cup "$LINES")\]'$PS1

To prevent tput from changing the exit code, you can explicitly save and reset it:

PS1='\[$(retval=$?;tput cup "$LINES";exit $retval)\]'$PS1

Note that the variable retval is local; it doesn't affect any retval variable you might have defined otherwise in the shell.

Since most terminals cup capability is the same \e[y;xH, you could also hardcode it:

share|improve this answer
How tput differ from many echo commands ? (Asking out of curiosity) – SHW Sep 1 '14 at 11:40
@l0b0, probably doesn't deserve a separate answer. I hope celtschk won't mind I edited his/her answer. – Stéphane Chazelas Sep 1 '14 at 11:45
'\[$(tput cup "$LINES")\]' works beautifully. Thanks! – l0b0 Sep 4 '14 at 7:37
There is an issue with tput: It seems to reset $exit_code. Fixed by using \[\e[$LINES;1H\]. – l0b0 Sep 8 '14 at 22:40
@l0b0: I've now added a version using tput that preserves the exit code. – celtschk Sep 11 '14 at 17:28

As a slight simplification to the previous answer, I found it easier to just run:

tput cup $LINES

in the beginning of .bashrc or .zshrc. It just does the job.


  • it only prints once, when you start your shell


  • when clearing screen with ^L, it doesn't print and aliasing clear to clear; tput ... doesn't help;
  • prompt moves elsewhere when terminal is resized
share|improve this answer

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.