18

I run gnome-terminal with unlimited scroll-line history
I want to dump text I can see in terminal to file and parse it

Is there a way to do it?

zetah
  • 2,981
  • 5
  • 19
  • 12

4 Answers4

9

If you want the whole contents of the terminal history:

In the gnome-terminal menu, Edit > Select All and then Edit > Copy. (Or use your favorite keyboard shortcut for the copy.)

Then paste anywhere.

If you want just part of the history, select with your mouse and then copy.

Greg Price
  • 2,836
  • 1
  • 23
  • 19
  • Yeah, I know but the scrollback is long and that's why I asked this question – zetah Sep 27 '11 at 06:27
  • 1
    @zetah: Use Edit -> Select All. Done. – Greg Price Sep 27 '11 at 06:30
  • I don't have a Select All option in my terminal (Linux Red Hat) – CodyBugstein Feb 14 '13 at 18:31
  • Imray: Are you using gnome-terminal, or a different terminal emulator? (I don't know what Red Hat's default is.) The original question here was about gnome-terminal. If gnome-terminal, what version? (I.e., what does `gnome-terminal --version` say?) – Greg Price Feb 24 '13 at 07:37
  • 1
    this everybody knows. Is there any way to make it permanent by making changes in any settings which will dump all the terminal contents to a user specified file so that we can avoid this manual copy paste thing every time? – uss Oct 01 '13 at 18:00
  • @sree: The original asker didn't know it! This is the answer to their question. – Greg Price Oct 13 '13 at 07:19
  • @sree: I don't know an answer to your question. I recommend you ask it as a question of its own. – Greg Price Oct 13 '13 at 07:20
8

You could use the unix script command to capture things as you go.

Gavin Brock
  • 5,027
  • 1
  • 30
  • 33
  • This is a great command, but it doesn't answer the question, which asks about dumping some text already visible in the terminal. – Greg Price Sep 27 '11 at 06:24
  • 2
    Can any of this tools capture what's already on screen, or I need to start it before? I mean all this current text have to be somewhere in memory and able to extract perhaps? – zetah Sep 27 '11 at 06:25
  • Sadly, script needs to be started in advance. It captures everything "visible" in the terminal - so things like passwords do not appear usually. – Gavin Brock Sep 27 '11 at 06:31
  • This is a beautiful command, thanks a lot. The typescript file opens with control characters, how do I escape these characters? – Vigneshwaren Feb 18 '14 at 07:27
  • 1
    could you please update link for a script ? or preferably write script here ?site in a link is not reachable anymore – mauek unak Oct 30 '17 at 15:07
4

If it's the output of a program that you want to capture and parse, simply redirect (>) it into a file

program_with_lots_of_output > output.log

and then parse it. Append a 2>&1 to that if you want standard error as well.

If you want a screen capture (i.e. including input), use the script program.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
1

You may want to use the 'tee' command. Tee bifurcates out stdout and makes a copy out the output in a file. So you can see the output and have the output stored also. Example:

ls | tee ls_out

Anz
  • 594
  • 1
  • 4
  • 15