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

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


当前回答

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

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

其他回答

CMD + K适用于macOS。它清除整个终端输出,但环境仍然存在。

删除最后一个输出:

⌘ + L

清空终端:

⌘ + K

手动清除终端。

⌘+K

Command+K用于较新的键盘

从shell脚本中清除终端;

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

漂亮的方法是printf '\33c\e[3J'

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

一个组合对我有用——

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

这将清除缓冲区和屏幕。