2

I have ran several commands in an xterm. I can scroll up and see the output but now I want to save that output. But I did not use screen or script or output-redirection for these past commands. Is it possible to save the output now? (I am using terminator, so if there is a command for 'select-all' that would suffice for my purpose.)

I cannot run the same commands again. Of course I can select the text with a mouse and then paste it in a file, but it is several thousand lines long, so I was wondering whether there is any easier method.

2 Answers 2

0

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.

0

This isn't perfect, and it's a little fiddly and dangerous, but:

first, get any other terminals out of the way / minimised / off your current desktop, to minimise the number of places you can accidentally paste thousands of lines into.

Then, in the terminal you want to copy from, do:

cat > /dev/null

This way, if while trying to get all the text selected you accidentally middle-click paste, your shell won't try to run thousands of lines as shell commands (which could potentially be very bad).

Set up the place where you want to paste the text into, and leave it ready to accept the pasted text - this can be a GUI text editor, another terminal set to do cat > savedfile.txt, etc.

Then:

  1. Show the scroll bar in xterm (skip if you've already got a scroll bar):

First, if possible, resize your terminal to be very slightly wider than it was (if you cannot do this, it is possible that 2 or 3 characters from the end of long lines will be lost -- experiment with this in harmless xterm if that's a problem).

Hold down ctrl and middle-click (and hold the mouse button down) somewhere in the terminal to bring up the menu

From the menu, choose "enable scroll bar"

Note: xterm will freeze and appear to do nothing for a long time. This is normal; it's just having to shove thousands of lines of text over by a bit to make room for the scroll bar. After a while a scroll bar will appear at the side of the terminal.

  1. Scroll all the way to the top (or the top of the part you want to save). Note that xterm's scroll bar is the old school X11 type of scroll bar, which is a bit counterintuitive to anyone who wasn't around when it was invented:

There is a blank region, and a small grey-ish region (if there is a lot of text, the grey-ish part might be only a single pixel thick).

The grey thing is the... whatever you call the "you are here" grabby thing on a modern scroll bar.

Unlike modern scroll bars, all three mouse buttons do something specific here:

  • Left-clicking anywhere on the scroll bar (even the grabby thing!) scrolls down by a bit. Left-click dragging does nothing.
  • Right-clicking anywhere on the scroll bar (even the grabby thing) scrolls up a bit. Right-click dragging does nothing.
  • Middle-clicking anywhere on the scroll bar immediately jumps to that location. Middle-click dragging moves the grabby thing to where you drag it.

So, to go all the way to the top, middle-click near the top and drag upwards to ensure that the grabby thing goes as far up as possible. You can confirm that you're at the top by pressing shift+pageup - if you don't go any higher up, that is as far back as the scrollback buffer goes (and anything earlier than that point is probably lost forever).

  1. Select some text, any text: left-click some text at the beginning of the region you want to save. You don't need to select much; even a few characters will do.

  2. Scroll all the way to the bottom: you use middle-click on the scroll bar again, or you can just type some text and xterm will jump to the bottom automatically.

  3. (DANGEROUS PART BEGINS) Right-click anywhere after the text you want to save. This will extend the marked selection all the way from the text you marked at the top, to the bottom. You now have a massive amount of text selected, so be VERY CAREFUL where you click, as this huge block of text will be immediately pasted anywhere you middle-click. Note that unless your xterm is set to "select to clipboard", this text is NOT on the clipboard and will not paste with ctrl+v! It is in the primary selection buffer, which is different (and is also very old, like the design of the xterm scrollbar).

  4. Go to the place you want to paste your text, without middle-clicking anywhere along the way. If your paste destination is vim or any other editor where lots of keyboard inputs do special things, be VERY sure it is ready to accept the paste, as if it is not in insert mode and you middle-click, bad things will happen (it is probably better not to use vim for this).

  5. When you are very sure the thing you have the mouse pointer over will happily accept thousands of lines of text, middle click the mouse once, and then wait for the pasting to finish.

  6. IMMEDIATELY select something else with the mouse, like a single character in another terminal. Once you have selected something else, middle-clicking is no longer hazardous.

Note: It may be safer to set "select to clipboard" in the source and (if applicable) destination xterm, as then middle-clicking won't be as hazardous, but there seem to sometimes be issues with size limits in the clipboard (i.e. limits which don't seem to affect the primary selection buffer). Feel free to test this.

You must log in to answer this question.

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