Lets say, I have a bunch of text in my Terminal session since the window was first opened (or since the last "clear" command was used), and exactly all of that is what I want in a text file.

Instead of manually 'selecting all' and copying from my terminal window then pasting into a text editor to take a "snapshot", what is the command equivalent of doing all this?

2 Answers 2


it seems the script command may be your friend but you need to start that way: https://askubuntu.com/questions/216322/how-can-i-capture-text-from-a-specific-terminal-and-redirect-it-to-a-log-file-wh or from man script script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive 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.

This depends on your terminal emulator.

If you use KDE konsole, you can use Save Output As... in the File menu. (By default, no keyboard shortcut, but you can use CtrlShiftF10 followed by a.)

If you use gnome-terminal, you can select the entire scrollback using Select All under the Edit menu (again, no default shortcut). Then you can use the xsel utility (or equivalent) to dump the selection to a file.

xterm (at least, the version installed on my machine) has a print-immediate() action, which can be triggered from the mainMenu. By default, that sends the entire scrollback plus the currently visible window to a file named XTerm with a timestamp appended. The filename prefix can be set with the printFileImmediate resource, and the data saved is affected by the printModeImmediate and printOptsImmediate resources.

Alternatively, you could select all text and then use the xsel technique as above, but I don't know of a convenient way to select all with xterm.

See also: man xterm man xsel as well as the relevant documentation for konsole, gnome-terminal, or the terminal emulator you usually use.

  • I'm using the stock Terminal with Ubuntu, and I'm looking for a simple command solution, so this can be done easily and within a bash script Aug 19, 2015 at 3:04
  • In other words, my bash script is starting with executing a "clear", it will run its thing, THEN I'd like to do a "save all text written on current terminal window into a text file" function at the end, which will of course have to be all automatic as an internal command. Aug 19, 2015 at 4:20
  • @user3125996: You cannot ask bash to save the output from a script because bash has no idea what that output is. It doesn't intervene; when bash runs a utility, it hands the utility open file descriptors for whatever stdin, stdout and stderr are redirected to, and after that the utility reads and writes from those file descriptors. Even bash does the same thing; it just sends its output to a file descriptor. The only program which has a model of the "current terminal window" is the terminal emulator, and you communicate with the terminal emulator through its menus.
    – rici
    Aug 19, 2015 at 5:12
  • ... Of course, you could redirect the output of the script to a file. You could even use tee to redirect it to a file as well as sending to stdout. That won't capture any input from stdin, but perhaps there isn't any. Or you can use script, which opens a subshell through a pseudotty and collects the raw output, including terminal formatting codes, into a logfile. The formatting codes make the logfile a bit annoying to deal with, but it's possible.
    – rici
    Aug 19, 2015 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.