清除真正的终端屏幕 [英] Clear a terminal screen for real

查看:312
本文介绍了清除真正的终端屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用明确在终端上的命令只有傻瓜用户误以为屏幕已被清除......你仍然可以看到从previous命令时输出您滚动使用鼠标。这使得生活困难,当你在文本的海啸淹没。

Using the clear command on the terminal only fools the user into thinking the screen has been cleared...you can still see output from the previous commands when you scroll using the mouse. This makes life difficult when you are drowning in a tsunami of text.

各种解决办法(逃避code等),可以在互联网上找到的只有变化是什么明确的命令已经这样做。

Various solutions (escape code etc.) which can be found on the internet are only variations of what the clear command already does.

那么,如何清除的bash终端的内容在Ubuntu是真的吗?

So how do you clear the contents of the bash terminal in Ubuntu for real?

推荐答案

使用下面的命令做了清晰的屏幕,而不是仅仅增加新的生产线......

Use the following command to do a clear screen instead of merely adding new lines ...

printf "\033c"

是的这是在bash提示符下一个printf的

yes that's a 'printf' on the bash prompt.

您可能会想,虽然定义别名...

You will probably want to define an alias though...

alias cls='printf "\033c"'

说明

\033 == \x1B == 27 == ESC

所以,这成为< ESC&以及c 这是VT100逃生code复位终端。 这里是在终端转义codeS一些更多的信息。

So this becomes <ESC>c which is the VT100 escape code for resetting the terminal. Here is some more information on terminal escape codes.

下面是做这件事的一些其他方法...

Here are a few other ways of doing it...

printf "\ec" #\e is ESC in bash
echo -en "\ec" #thanks @Jonathon Reinhart.
# -e    Enable interpretation of of backslash escapes
# -n    Do not output a new line

KDE

以上未在KDE控制台上工作(所谓的Konsole),但有希望!使用下面的命令序列,以清除屏幕并滚动回缓冲区...

KDE

The above does not work on the KDE console (called Konsole) but there is hope! Use the following sequence of commands to clear the screen and the scroll-back buffer...

clear && echo -en "\e[3J"

也许使用下面的别名在KDE ...

Or perhaps use the following alias on KDE...

alias cls='clear && echo -en "\e[3J"'

我得到的滚动回从清除命令这里

这篇关于清除真正的终端屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆