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)上不起作用,但还是有希望的!使用以下命令序列来清除屏幕和向后滚动缓冲区...
Use the following command to do a clear screen instead of merely adding new lines ...
printf "\033c"
yes that's a 'printf' on the bash prompt.
You will probably want to define an alias though...
alias cls='printf "\033c"'
Explanation
\033 == \x1B == 27 == ESC
So this becomes <ESC>c which is the VT100 escape code for resetting the terminal. Here is some more information on terminal escape codes.
Edit
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
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...
在连接设置中的“窗口 -> 行为”下,您会找到一个设置“系统菜单出现在 ALT 上”独自的”。然后CTRL + L,ALT,l(这是一个小写的L)将滚动屏幕,然后清除回滚缓冲区。
(与OP相关,因为我正在连接到Ubuntu服务器,但无论您的服务器运行什么,显然也相关。)
None of the answers I read worked in PuTTY, so I found a comment on this article:
In the settings for your connection, under "Window->Behavior" you'll find a setting "System Menu Appears on ALT alone". Then CTRL + L, ALT, l (that's a lower case L) will scroll the screen and then clear the scrollback buffer.
(relevant to the OP because I am connecting to an Ubuntu server, but also apparently relevant no matter what your server is running.)
Tested on xterm and VT100. It also helps after an abnormal program termination.
Keeps the command buffer, so up-arrow will cycle through previous commands.
I know the solution employing printing of new lines isn't much supported, but if all else fails, why not? Especially where one is operating in an environment where someone else is likely to be able to see the screen, yet not able to keylog. One potential solution then, is the following alias:
alias c="printf '\r\n%.0s' {1..50}"
Then, to "clear" away the current contents of the screen (or rather, hide them), just type c+Enter at the terminal.
With KDE and Ubuntu 12.04 LTS and the "Konsole" terminal, none of the posted answers work. However, pressing default keyboard shortcut CTRL+Shift+X does work! Source:
发布评论
评论(12)
使用以下命令进行清屏,而不仅仅是添加新行...
是的,这是 bash 提示符上的“printf”。
不过,您可能想要定义一个别名...
说明
因此,这将变为
c
,它是用于重置终端的 VT100 转义码。 这里是一些有关终端转义码的更多信息。编辑
这里有一些其他的方法...
KDE
上面的方法在 KDE 控制台(称为 Konsole)上不起作用,但还是有希望的!使用以下命令序列来清除屏幕和向后滚动缓冲区...
或者也许在 KDE 上使用以下别名...
我从 这里。
Use the following command to do a clear screen instead of merely adding new lines ...
yes that's a 'printf' on the bash prompt.
You will probably want to define an alias though...
Explanation
So this becomes
<ESC>c
which is the VT100 escape code for resetting the terminal. Here is some more information on terminal escape codes.Edit
Here are a few other ways of doing it...
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...
Or perhaps use the following alias on KDE...
I got the scroll-back clearing command from here.
尝试
重置
。它会清除终端屏幕,但可以通过箭头或您拥有的任何键绑定来访问之前的命令。Try
reset
. It clears up the terminal screen but the previous commands can be accessed through arrow or whichever key binding you have.这样就可以了!
That will do the trick!
我读到的答案在 PuTTY 中都不起作用,所以我在 本文:
在连接设置中的“窗口 -> 行为”下,您会找到一个设置“系统菜单出现在 ALT 上”独自的”。然后CTRL + L,ALT,l(这是一个小写的L)将滚动屏幕,然后清除回滚缓冲区。
(与OP相关,因为我正在连接到Ubuntu服务器,但无论您的服务器运行什么,显然也相关。)
None of the answers I read worked in PuTTY, so I found a comment on this article:
In the settings for your connection, under "Window->Behavior" you'll find a setting "System Menu Appears on ALT alone". Then CTRL + L, ALT, l (that's a lower case L) will scroll the screen and then clear the scrollback buffer.
(relevant to the OP because I am connecting to an Ubuntu server, but also apparently relevant no matter what your server is running.)
清洁可见屏幕
<前><代码>清除
清洁屏幕并清除缓冲区
清洁并延迟 1 秒
<预置><代码>重置
干净且无 1 秒延迟
Clean the visible screen
Clean screen and clear buffer
Clean and 1-sec delay
Clean without 1-sec delay
我最喜欢的人类友好命令是:
在 xterm 和 VT100 上测试。它在程序异常终止后也有帮助。
保留命令缓冲区,因此向上箭头将循环显示先前的命令。
My favorite human friendly command for this is:
Tested on xterm and VT100. It also helps after an abnormal program termination.
Keeps the command buffer, so up-arrow will cycle through previous commands.
以下链接将解释如何使该别名永久存在,这样您就不必继续输入它。
https://askubuntu.com/questions/17536/how-do-i-create-a-permanent-bash-alias
这些是该链接中详细说明的步骤。
vim ~/.bashrc
或gedit ~/.bashrc
或您喜欢的任何文本编辑器alias cls='printf "\033c"'
在文件底部。 ~/.bashrc
(是的,.
和~
之间应该有一个空格)我不相信这些信息只是传递它。
The following link will explain how to make that alias permanent so you don't have to keep typing it in.
https://askubuntu.com/questions/17536/how-do-i-create-a-permanent-bash-alias
These are the steps detailed at that link.
vim ~/.bashrc
orgedit ~/.bashrc
or what ever text editor you likealias cls='printf "\033c"'
at the bottom of the file. ~/.bashrc
(and yes there should be a space between.
and~
)I take no credit for this information just passing it along.
我知道采用打印新行的解决方案并没有得到太多支持,但如果其他一切都失败了,为什么不呢?特别是当一个人在其他人可能能够看到屏幕但无法进行键盘记录的环境中操作时。那么,一种可能的解决方案是使用以下别名:
然后,要“清除”屏幕的当前内容(或者更确切地说,隐藏它们),只需在终端键入
c+Enter
即可。I know the solution employing printing of new lines isn't much supported, but if all else fails, why not? Especially where one is operating in an environment where someone else is likely to be able to see the screen, yet not able to keylog. One potential solution then, is the following alias:
Then, to "clear" away the current contents of the screen (or rather, hide them), just type
c+Enter
at the terminal.只需补充一下,
tmux
滚动缓冲区不会通过clear
、reset
或printf
清除。您需要:clear-history
。请参阅链接。Just to add that
tmux
scroll buffer does not clear withclear
,reset
orprintf
. You need to:clear-history
. See link.对于 KDE 和 Ubuntu 12.04 LTS 以及“Konsole”终端,发布的答案都不起作用。但是,按默认键盘快捷键 CTRL+Shift+X 确实有效!来源:
https://bugs.kde.org/show_bug.cgi?id=288913
With KDE and Ubuntu 12.04 LTS and the "Konsole" terminal, none of the posted answers work. However, pressing default keyboard shortcut CTRL+Shift+X does work! Source:
https://bugs.kde.org/show_bug.cgi?id=288913
这适用于 Linux 机器
This works in Linux Machines
编译这个应用程序。
Compile this app.