我知道“清除”当前屏幕的清除命令,但它只是通过打印大量换行来做到这一点-清除的内容只是向上滚动。

是否有一种方法可以完全擦除终端之前的所有输出,以至于我即使向上滚动也无法到达它?


当前回答

我不能得到任何以前的答案工作(macOS)。

一个组合对我有用——

IO.write "\e[H\e[2J\e[3J"

这将清除缓冲区和屏幕。

其他回答

我不能得到任何以前的答案工作(macOS)。

一个组合对我有用——

IO.write "\e[H\e[2J\e[3J"

这将清除缓冲区和屏幕。

删除最后一个输出:

⌘ + L

清空终端:

⌘ + K

做正确的事;把事情做好!

清除上一个标记:命令+ L

清除到以前的书签:选项+命令+ L

可以开始:Command + K

手动清除终端。

⌘+K

Command+K用于较新的键盘

从shell脚本中清除终端;

/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'

把它放在你的.bash_profile或.bashrc文件中:

function cls {
    osascript -e 'tell application "System Events" to keystroke "k" using command down'
}