Can you rescue a shell from an accidental "yes" command?

Scenario: I’m running a bunch of commands, some of which prompt for "yes/no" answers. I accidentally type yes as a command instead of as a response to a prompt. OOPS. Now my shell looks like this:

$ yum install -y something-important
... useful output I want to go back and refer to, perhaps multiple times
$ yes
y
y
y
y
y
y
y
y
y
y
y
... there are tens of thousands of lines... oh god, Y??

I successfully halt the yes command after realizing what happened, but the damage is already done. I was in the middle of an intense shell session, and now I’ve lost the ability to scroll back up for relevant output! Obviously the previous text is all still there, but it’s essentially inaccessible because it’s dwarfed by all the y. Something like clear will help remove the unsightly y torrent from my screen, but it won’t help me get back to the previous session state.

How can I rescue this session’s previous output to still be useful?

Asked By: Indigenuity

||

Graphical terminal emulators normally have a limited number of strings to keep in the scrollback buffer, so if your previous lines have been rotated they are lost. You could increase the number of lines being kept or some terminals even allow to have an unlimited scrollback.

Answered By: Artem S. Tashkinov
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.