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?
And to scroll down in the terminal, use Shift + PageDown.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With