5

I recently switched to Ubuntu from Windows10. In the windows command prompt, you could scroll past the end of the line and make the last line appear in the top of the screen. I think it's really helpful in keeping concentration at the work you're currently doing as you don't have to see (and thus not having to worry) about what you wrote before.

Unfortunately, I can't get my Ubuntu 20.04 terminal do this. I searched this site and other sites for a couple of days and could not find any solution. Someone please help me out.

I want to scroll beyond the last line in the terminal so that what I'm currently writing stays on top or at least in the middle of the screen.

Thanks in advance!

3
7

Instead of scrolling, you can use the Ctrl+L shortcut to clear your terminal screen and have the prompt on the top of the terminal. Using this shortcut, you will be able to scroll back to the previous terminal output.

Alternatively, you can make use of the clear command and run:

clear -x

to clear your terminal screen the same way the Ctrl+L shortcut does. Note the use of the -x flag. If you don't use that, the terminal's scrollback buffer will also be cleared, so you won't be able to scroll back to the previous output.

0

You may find adding this script to your .bashrc to be useful:

export PROMPT_COMMAND="read -n1"
export PS1="$(clear -x)$PS1"

This will cause bash to wait for a keypress and then immediately clear the screen after each command. Thus, your prompt will always be at the top of the terminal window.

EDIT: replaced raw hex escapes with process substitution to be more portable.

2
  • I think the first $ in PS1 should be escaped, no? (export PS1="\$(clear -x)$PS1") – jazzpi Aug 31 '20 at 9:23
  • @jazzpi no I intentionally left it like that, I want clear -x to only run once, and have that output stored forever. – vikarjramun Aug 31 '20 at 14:54
0

Solution


Go to end of the line: Ctrl + E. Remove the forward words for example, if you are middle of the command: Ctrl + K. Remove characters on the left, until the beginning of the word: Ctrl + W. To clear your entire command prompt: Ctrl + L.

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.