8

I have currently decided to test my double monitors in the vertical configuration, and I came across a problem that I had never had before: the input line on my terminal is too far down the screen!

I was wondering if there is a way to make the output scroll downwards, so that the input line stays at the top.

e.g., a normal terminal view looks like this:

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=46 time=28.3 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=46 time=13.7 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=46 time=19.1 ms
64 bytes from 8.8.8.8: icmp_req=4 ttl=45 time=20.8 ms
64 bytes from 8.8.8.8: icmp_req=5 ttl=45 time=15.6 ms
64 bytes from 8.8.8.8: icmp_req=6 ttl=46 time=15.3 ms
64 bytes from 8.8.8.8: icmp_req=7 ttl=46 time=15.3 ms
64 bytes from 8.8.8.8: icmp_req=8 ttl=45 time=14.3 ms
64 bytes from 8.8.8.8: icmp_req=9 ttl=45 time=14.3 ms
64 bytes from 8.8.8.8: icmp_req=10 ttl=45 time=15.5 ms
64 bytes from 8.8.8.8: icmp_req=11 ttl=45 time=16.9 ms
64 bytes from 8.8.8.8: icmp_req=12 ttl=45 time=16.3 ms
64 bytes from 8.8.8.8: icmp_req=13 ttl=45 time=20.0 ms
^C
--- 8.8.8.8 ping statistics ---
13 packets transmitted, 13 received, 0% packet loss, time 12017ms
rtt min/avg/max/mdev = 13.773/17.391/28.343/3.812 ms
me@my_computer:~$ 

and instead I would like to have something like this:

me@my_computer:~$ 
rtt min/avg/max/mdev = 13.773/17.391/28.343/3.812 ms
13 packets transmitted, 13 received, 0% packet loss, time 12017ms
--- 8.8.8.8 ping statistics ---
^C
64 bytes from 8.8.8.8: icmp_req=13 ttl=45 time=20.0 ms
64 bytes from 8.8.8.8: icmp_req=12 ttl=45 time=16.3 ms
64 bytes from 8.8.8.8: icmp_req=11 ttl=45 time=16.9 ms
64 bytes from 8.8.8.8: icmp_req=10 ttl=45 time=15.5 ms
64 bytes from 8.8.8.8: icmp_req=9 ttl=45 time=14.3 ms
64 bytes from 8.8.8.8: icmp_req=8 ttl=45 time=14.3 ms
64 bytes from 8.8.8.8: icmp_req=7 ttl=46 time=15.3 ms
64 bytes from 8.8.8.8: icmp_req=6 ttl=46 time=15.3 ms
64 bytes from 8.8.8.8: icmp_req=5 ttl=45 time=15.6 ms
64 bytes from 8.8.8.8: icmp_req=4 ttl=45 time=20.8 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=46 time=19.1 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=46 time=13.7 ms
64 bytes from 8.8.8.8: icmp_req=1 ttl=46 time=28.3 ms
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.

I could not find any such documentation or question on the forums. If anyone has an idea, please let me know! (also if you think it's not possible)

Thanks!

PS: I'm using Ubuntu 12.04

5

I found one nice tip from which you can start. You must to play with bash:

To set it up:

$ bash    # try this in a subshell since ^C seems to cause it to exit
$ f () { sed "1s/^/$(tput cup 0 0)/;s/^/$(tput il1)/"; }
$ PROMPT_COMMAND='tput cup 0 0;tput il1; echo'
$ exec > >(f)

Press enter one extra time and it's ready to try. Sometimes the output and the prompt are out of order and there may be other weirdness, but it's kind of an interesting thing to try.

Source: Reversed Terminal / Command line window.

See also:

  • i think it is just as my answer – nux Mar 9 '14 at 20:01
  • @nux You think, but is not. It's Dennis Williamson's answer, as I specified in my source ;) – Radu Rădeanu Mar 9 '14 at 20:04
  • ok never mind , i edit it so @cd can copy and paste in his terminal to test what it can do . – nux Mar 9 '14 at 20:07
  • I had to accept this answer indeed due to the reference! But thanks nux too! – cd127 Mar 12 '14 at 10:25
4

After searching for this good question , i found this commands and hope it can help you , so it can help you focusing on the top of the terminal when writing a command .

In terminal try :

 f () { sed "1s/^/$(tput cup 0 0)/;s/^/$(tput il1)/"; }
 PROMPT_COMMAND='tput cup 0 0;tput il1; echo'
 exec > >(f)

Reference Site

4

Another trick would be to pass your command's output through tac which is like cat but prints in reverse order:

terdon@oregano ~ $ ping -c 5 8.8.8.8 | tac
rtt min/avg/max/mdev = 88.906/91.678/94.948/2.129 ms
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
--- 8.8.8.8 ping statistics ---

64 bytes from 8.8.8.8: icmp_seq=5 ttl=42 time=88.9 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=42 time=92.8 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=42 time=90.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=42 time=91.5 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=42 time=94.9 ms
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.

Note that I had to specify a maximum ping number (-c 5) because otherwise the ping command won't exit and the pipe will break. Anyway, tac is very useful for this type of thing.

  • I like the tac - didn't know about it. Unfortunately as you said yourself, it has some limitations. And it does not set the command line to the top of the shell! – cd127 Mar 12 '14 at 10:26
  • @cd127 no it doesn't, I hadn't realized you also wanted to move the prompt. – terdon Mar 12 '14 at 10:30

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.