Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was working on a shell and got some weird exceptions in my program.

Just as a reference, I want to save all that is there on my shell to a text file. I do not just want the command history but also all the results that those commands produced at the shell.

Is there some built-in utility to do this? I have kept the shell open for now, so that I can take the backup. Also, I am using xterm and it does not allow selecting all the way upto the top of the shell, so the ultimate way is to take the backup one screen at a time. Any suggestions?

The shell looks like

alt text

share|improve this question
What shell are you using? Bash, Bourne, Korn, Z, C, etc.? I think when you're saying "shell" you mean "terminal" instead. What error message did you get? You want to save a copy of output after-the-fact? Normally, before-hand you could use script to save the input and output. – Dennis Williamson Sep 2 '10 at 18:58
Also, are you actually using "xterm", or are you using that to refer to something like Konsole or the like? The terminal emulator Konsole (and others like it) have the ability to do logging, and such. – Matt Sep 2 '10 at 19:02
up vote 3 down vote accepted

I think script may be of some use here

And xterm should have the ability to select al you want. I'd check your flags, including -sl NUMBER, -sb

share|improve this answer
script is a nice find, but it has to be started beforehand. – Lazer Sep 2 '10 at 19:28

To copy the whole window content, including the scrollback, select the last line (by dragging the left mouse button or by triple-clicking the left mouse button), then use the scroll bars to scroll to the top and right-click in the top left corner. Note that unlike the methods below, this will only show the final result as plain text: it won't show things that were displayed then erased, and it won't show colors and other formatting.

To avoid this in the future you can try this.

  • Run your session inside script. Logging a shell session is script's goal in life.

  • Run your session inside screen. It has several commands that can help you, including C-a h to write a “screenshot” into a file, and C-a H to start logging all subsequent output to a file.

  • Some terminal emulators have a logging facility. In xterm, you can turn it on by checking “Log to File” in the Ctrl+left-mouse-button menu; all subsequent terminal output is logged. With the -l option, this is done for the whole session.

share|improve this answer
+1 And moved the part that might help in this case (wanting to capture an existing session) to the top – Nifle Sep 2 '10 at 20:13

You must log in to answer this question.

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