It is deeply frustrating trying to read text that appears at the bottom of a window. Whenever I am using a text editor such as Gedit, I pad the bottom of the currently open file with 20 or 40 empty lines to prevent my attention from being forced to the bottom of the window.

Unfortunately, when I am using interactive shells, such as python or bash, the same workaround is not possible.

I want to find a way to control which row the cursor of the Ubuntu terminal sticks to once the previous rows have been filled.

There is a similar question here, but the accepted answer does not address the problem.

Any suggestions appreciated.


Here is an example of two Gedit windows.

enter image description here

The first screenshot depicts a window that is almost full. One or two more lines and I will have to spend the next hour of work staring at the bottom of the window.

enter image description here

The second screenshot depicts the solution. I add blank lines to the bottom of the file so that the relevant 3rd line is no longer at the bottom of the screen but in the middle.

I am looking for a way to achieve a similar effect within the terminal so that whatever shell I'm using does not force my attention to the bottom of the terminal window, but instead allows me to keep my vision comfortably in the window's vertical center.

  • 1
    Are you asking for a tool to browse already exisiting text in a bash or python window, or a tool to monitor text that is written by a running process (so that there are no lines after the currently wirtten line)? – sudodus Apr 13 '20 at 20:57
  • 1
    Do I understand correctly that you want a text mode editor with this feature (that you will never write below the middle of the window)? – sudodus Apr 13 '20 at 21:28
  • 2
    Would you consider resizing the window so its bottom does not reach the bottom of the display? – twisteroid ambassador Apr 14 '20 at 7:07
  • 2
    Am I missing something, or both solutions in the answers below just waste the lower portion of the terminal window*? Yeah, it is confy, but you'll have less terminal to type. Just resizing the window so that it rests on the upper half of the screen does the trick to me. Again, am I missing something? * He metioned Ctrl+Shift+T, so he is using Gnome Terminal and not a text screen outside X. – Henrique Apr 14 '20 at 15:43
  • 2
    I found way back that running the shell inside Emacs (M-x shell) had pretty much the effect you described. I didn't like it but you might. – Thorbjørn Ravn Andersen Apr 14 '20 at 16:46

You can change your terminal prompt so that it echos five carriage returns and then uses an ansi escape sequence to move back up five lines before it finishes the rest of the prompt. If this works for you, you can put it in your .bashrc to make it permanent. Copy and paste this into your terminal :

PS1='\n\n\n\n\n\[\033[5A\]\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'

The '\n\n\n\n\n' moves down five lines and '[\033[5A]' moves back up five lines. You can modify both of those if you want more space.

  • This works very well. I will have to read a bit to understand the different characters are doing. What is the purpose of ${debian_chroot:+($delete_chroot)}? – BLUC Apr 14 '20 at 22:20
  • 1
    That's what my $PS1 normally is before I add code to the beginning. Try : echo $PS1 ;) – bashBedlam Apr 14 '20 at 22:23
  • 2
    The debian_chroot thing is for when you use Debian-style chroot tools: when working within a chrooted environment, the name of that environment will appear (within parentheses) prefixed to the regular prompt. This is to remind you of the fact that you are working within a chroot, and e.g. /etc is not the real /etc but actually something like /top/dir/of/chroot/environment/etc. – telcoM Apr 15 '20 at 5:48

You could try using tput to change your terminal's scroll region:

tput csr 1 $((LINES/2))

If the shell's checkwinsize option is enabled, then $LINES should get updated if the terminal is resized - however in order to re-run the tput csr command when that happens, you will need to capture the SIGWINCH signal. You could add such a trap to your interactive shell initialization file ~/.bashrc as follows:

trap 'tput csr 1 $((LINES/2))' WINCH ; kill -s WINCH $$

The second part of the command kill -s WINCH $$ sends an initial SIGWINCH so that the tput csr command gets run when the shell is first invoked as well.


  • Thank you for answering. This is definitely the cleanest way to solve the problem. I noticed a few side effects though- after setting the scroll region I can no longer scroll up and see previous commands, and I can't scroll to see the full output of commands which take up more than LINES*m/n lines. It also breaks the scroll within man, although only after the user scrolls down and then back up. – BLUC Apr 14 '20 at 17:06

Why not just use the clear command from time to time?

  • 3
    Ctrl-L achieves the same effect in most (all?) shells. More convenient :) – marcelm Apr 14 '20 at 17:37
  • That is a useful although temporary solution. – BLUC Apr 14 '20 at 22:08
  • @marcelm I never new that. It is very useful to know since it works on all the interactive shells I use, including python and lua. – BLUC Apr 14 '20 at 22:09
  • 1
    @marcelm I use Linux (and Bash) sine 1998 and never knew that. Thanks! – Henrique Apr 14 '20 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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