Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: jump to bottom of terminal

Tags:

bash

I want to do the same thing that the "top" command does on exit:

Print something on the screen, then jump to the bottom of the terminal window so that the prompt is located on the bottom line.

(If I just print 1000 empty lines I will lose what I have printed on the screen, so I need a more elegant solution to get to the bottom of the terminal window)

How to achieve this in bash?

like image 976
Roland Seuhs Avatar asked Apr 09 '18 12:04

Roland Seuhs


People also ask

How do I scroll to the bottom of terminal?

And to scroll down in the terminal, use Shift + PageDown.

How do you get to the bottom in less command?

You can navigate the file contents using the up and down keys, or using the space bar and b to navigate page by page. You can also jump to the end of the file pressing G and jump back to the start pressing g .

How do you go to the last line in less?

Pressing F while less is open is identical to pressing Ctrl + End . It will continually read and load the end of the file. This is very useful for a growing log file.

How do I scroll higher in terminal?

For most users, you should be able to scroll up and down, one line at a time using Shift+UpArrow or Shift+DownArrow. To jump an entire page at a time, try Shift+PageUp or Shift+PageDown. If these commands don't work, it's likely your terminal is using different keybindings.


1 Answers

tput cup $(tput lines) 0 

In general, tput cup X Y moves the cursor to position X, Y (counting from the upper left corner.) tput lines or tput li gives you the max X value on the current terminal. Note that tput li relies on a terminfo capability that may not be present, but tput cup 1000 0 should have the same effect (assuming your tty has less than 1000 lines!) If you want to print something on the screen starting at a particular location, there's really no need to "jump to the bottom", you can do things like: clear; tput cup 5 0; printf hello; sleep 1; tput cup 5 0; printf world; tput el; tput cup $(tput li) 0

like image 125
William Pursell Avatar answered Sep 30 '22 18:09

William Pursell