Clear a terminal screen for real

2019-01-07 01:23发布

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.

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

So how do you clear the contents of a terminal in Linux for real?

10条回答
Animai°情兽
2楼-- · 2019-01-07 02:07

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

查看更多
Melony?
3楼-- · 2019-01-07 02:07

Compile this app.

#include <iostream>
#include <cstring>

int main()
{
  char str[1000];
  memset(str, '\n', 999);
  str[999] = 0;
  std::cout << str << std::endl;
  return 0;
}
查看更多
对你真心纯属浪费
4楼-- · 2019-01-07 02:11
echo -e "\e[3J"

This works in Linux Machines

查看更多
再贱就再见
5楼-- · 2019-01-07 02:13
tput reset

That will do the trick!

查看更多
登录 后发表回答