Let's say I'm running a script that outputs a lot of content. Halfway through I want to clear the output so that if I scroll up, I only see output created after that point.

On Mac OS X Terminal, I can just use Command-K but there doesn't seem to be an equivalent for the Ubuntu terminal.

Here's what I've found:

  • clear && echo -en "\e[3]" sends a reset and clears out the entire window, but that requires me to have access to the bash prompt
  • Control-L clears the current content but doesn't appear to work while a process is running and it only scrolls the window down and doesn't clear out previous content.

I'm currently using the default terminal included with the Windows subsystem Ubuntu install. Is there any command I can send to the terminal that force-resets everything?

Alternatively, is there a third-party terminal that supports this — ideally one that also offers other advantages like tabs and improved text copying/pasting?

  • What do you mean by "the Ubuntu terminal"? Is it gnome-terminal? konsole? xterm? or what you see after Ctrl+Alt+F1? Anyway, after you discover what tty or pts the process uses for output (readlink /proc/<PID>/fd/1), you can do like clear > /dev/pts/2 from another console to affect it. This is the Unix way where "everything is a file"; I don't know if something similar works in Windows Subsystem for Linux. Apr 23, 2018 at 19:27

1 Answer 1


It sounds like the problem is that some command/script is outputting some stuff you don't care about and some stuff you do care about.

I don't know enough about Windows to answer the "How to clear a terminal session with a keystroke" but I know enough about linux in general to give some suggestions on "How to make output more readable."

Have you considered the following "standard linux" ways of solving that problem?

A) Logging the output

your_command >> output.txt

This makes the output more permanent, you can also make an output1.txt, output2.txt, etc. and see if some change is doing what you want it to.

The >> operator in bash will change the output of the command/script from the console to a file in whichever directory you're working in. (You can also specify a path if you want it somewhere specific)

Better yet, if you wrote or can edit the script, you can setup logging in the script to organize the output into relevant files with timestamped file names etc.

B) Piping the output

your_command | less

This is better if you don't anticipate needing to refer to multiple "versions" of the output, and also don't expect to want to know the output later in the future.

While in the less program, you can jump to the text you care about. (Search in less is / then your search term)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .