0

In either Cygwin or gnome terminal, clear doesn't actually remove the previous output in the terminal. So when I run clear and then some programs, and search (using the search feature of the terminals) for some word in the output of the programs that are run after clear , it will also search in the output of the other commands previously run on the screen before clear.

How can i search in the output on a terminal screen since an arbitrarily chosen time point?

My current workaround is to open a new terminal to run the programs whose outputs I would like to search in. But is there a way without opening a new terminal?

Thanks.

  • This isn't AFAIK really doable, because searchable terminal history is entirely a clientside thing. You could look into modifying the terminal emulator to accept a certain escape sequence to purge the entire history, but I don't know of any that offer this functionality out of the box. – DopeGhoti Mar 29 '17 at 19:01
  • 1
    tput clear seems to do it, but I dont know why and I didn't test searching. – ctx Mar 29 '17 at 19:04
  • @ctx tput clear is the same as clear – roaima Mar 29 '17 at 19:13
  • Alternately you can use script(1) to save a copy of the session in a file and search that. i.e. script; ./prog1; ./prog2; exit; grep word typescript; rm typescript – Matthew Gauthier Mar 29 '17 at 20:07
  • tput init or tput reset, depending on the capabilities of the terminal. Sometimes reset works as well. – ridgy Mar 29 '17 at 21:25
-1

The features that you're mentioning sound very similar to what GNU Screen provides.

If you wish to search terminal output then you can make use of the copy-mode/scrollback feature. (CTRL-a ESC) then ? to reverse search and / to forward search.

I spend a very large (close to 100%) of my terminal time in GNU Screen.

By default the scroll back is set to 100 lines, this is easily increased by setting defscrollback to something higher in ~/.screenrc. New windows can be created (CTRL-a c) and switched between (CTRL-a n, or CTRL-a p).

It's something that has been around for decades and I hope it will be around for many more to come due to the vast array of features it provides which gives me a consistent layer no matter which terminal is flavour of the month.

  • 3
    I think this is the opposite of what the OP desires. They do not want the shell history search to include commands that have been followed by clear. – roaima Mar 29 '17 at 19:14
  • Then destroy the window. CTRL-a k or CTRL-d. Scroll back is there for searching or destroying. – Ed Neville Mar 29 '17 at 19:18
  • 1
    Not a good answer, the user, and others, want to know what the module is inside of the terminal to control the rendering without having to close and open a new window. clear, reset and history -c do not clear the searchable history within the terminal. – mibbit Sep 27 '18 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.