终端带有向下滚动的输出

我目前决定在垂直配置下测试我的双显示器,却遇到了一个以前从未遇到过的问题:终端的输入行太靠下了!
我想知道是否有办法使输出向下滚动,以便输入行保持在顶部。
例如,正常的终端视图如下:
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:~$ 

我希望有类似这样的东西:

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.

我在论坛上找不到任何相关的文档或问题。如果有人有想法,请告诉我!(也请告诉我如果你认为这不可能)

谢谢!

PS:我正在使用Ubuntu 12.04

3个回答

我找到了一个不错的提示,你可以从这里开始。你必须玩一下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.

来源:反转终端/命令行窗口

另请参阅:


我认为这就是我的答案。 - nux
你以为是这样,其实并不是。这个回答来自Dennis Williamson,就像我在我的信息来源中所指明的那样 ;) - Radu Rădeanu
没事,我编辑了一下,@cd可以复制粘贴到他的终端上测试一下它的功能。 - nux
我确实不得不接受这个答案,因为有参考资料!但还是要感谢nux! - cd127

在搜索了这个好问题之后,我找到了这些命令,希望它们能对你有所帮助,这样在输入命令时可以让你专注于终端的顶部。
在终端中尝试一下:
 f () { sed "1s/^/$(tput cup 0 0)/;s/^/$(tput il1)/"; }
 PROMPT_COMMAND='tput cup 0 0;tput il1; echo'
 exec > >(f)

参考 网站

另一个诀窍就是将命令的输出通过“tac”进行传递,它类似于“cat”,但以相反的顺序打印出来。
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.

请注意,我不得不指定一个最大的ping次数(-c 5),否则ping命令将不会退出并且管道会中断。无论如何,tac对于这种类型的事情非常有用。

我喜欢这个Tac-不知道它。不幸的是,正如你自己所说,它有一些限制。并且它不能将命令行设置为 Shell 的顶部! - cd127
@cd127 不,它不会移动提示,我之前没有意识到你也想要移动提示。 - terdon