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

When I want to ask question on Linux platform, I would always need to provide the screenshot of current shell.But taking snapshot,uploading, linking costs much, is there any command to extract text directly from the current shell?

share|improve this question
up vote 1 down vote accepted

You could just use the script command.

Taken from the manual:

The script utility makes a typescript of everything printed on your terminal.
It is useful for students who need a hardcopy record of an inter- active session as proof of an assignment, as the typescript file can be printed out later with lpr(1).

If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript.

If the argument command is given, script will run the specified command with an optional argument vector instead of an interactive shell.

Example (information in typescript file):

Script started on Mon Nov  2 21:13:17 2009
bash-3.2$ pwd
bash-3.2$ ps
  PID TTY           TIME CMD
  395 ttys000    0:00.02 -bash
  425 ttys000    0:00.00 script
  426 ttys001    0:00.01 /bin/bash -i
bash-3.2$ exit

Script done on Mon Nov  2 21:13:44 2009
share|improve this answer
+1 Very nice! That's about as simple as they get. – DaveParillo Nov 3 '09 at 2:46

screen can do this. Connect to a screen instance, run your shell commands, and get a "hardcopy" of the current terminal with the hardcopy screen command (type Ctrl-A, then press "h"). The output is usually saved in your home directory in ~/hardcopy.1, ~/hardcopy.2, etc.

If you need more than what's on the current screen, use screen's scrollback buffer.

  • Access it (get into "copy mode") by pressing Ctrl-A, then Esc.
  • Scroll up/down with Ctrl-U/Ctrl-D or the arrow keys or vim-style movement (j/k/l/h).
  • Get out of "copy mode" by pressing Esc.

Using "copy mode", you can select a block of text and get a hardcopy like this:

  1. Get into "copy mode" (press Ctrl-A, then Esc).
  2. Scroll to the start of the text you want to copy.
  3. Press SPACE. This marks the start.
  4. Scroll to the end of the text you want to copy.
  5. Press SPACE again. This fills the copy buffer and exits out "copy mode".
  6. Write the copy buffer to file (press Ctrl-A, then >). The copy buffer is written out to /tmp/screen-exchange.
  7. Copy /tmp/screen-exchange to whatever file you like:

    cp /tmp/screen-exchange ~/my.terminal.printout.txt

Your terminal's output is now in ~/my.terminal.printout.txt.

share|improve this answer
@~quack:its a little complicated :) – Jichao Nov 3 '09 at 2:35
screen is a very powerful utility, so yeah, it takes some getting used to. i've been using it a long time and am just now figuring this stuff out. if you were already a screen user, the "Ctrl-A, h" stuff wouldn't seem that complicated. – quack quixote Nov 3 '09 at 2:38

You must log in to answer this question.

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