Quite often, I'm in the following situation: I launch a command on bash (that takes lot of time to be processes) and I get a long output, which doesn't fit into the terminal and it can't be read even using the scrolling. The only way I have to read it is to redirect the output to a file. In order to do so, I have to relaunch the command, something that I want to avoid as I would take too much time.

I simply want to print on file the output that has been generated in the prevous command.

It there any way to do that?


PS: for example, I give

diff folder1 folder2 #the folders contain many files

wait 60 seconds, and after I decide to print the output

  • 1
    which terminal emulator do you use?
    – lese
    Commented Jan 25, 2016 at 14:31
  • 1
    @lese I use GNOME Terminal (v 2.31.3) and MATE Terminal (don't remember the version). I would be happy to change but I can't (no root privileges).
    – altroware
    Commented Jan 25, 2016 at 14:39
  • 1
    do you need root proviledges to change the gnome terminal configuration? I don't think so : )
    – lese
    Commented Jan 25, 2016 at 14:44
  • 1
    @lese Perhaps I should say I don't know how... :-$
    – altroware
    Commented Jan 25, 2016 at 14:47
  • 1
    @altroware Ok let me understand your problem. You executed a command, it gives you a very long output that you can't read even scrolling up your terminal screen. You want to save THAT GIVEN output to a file? Avoiding to execute the command again?
    – tachomi
    Commented Jan 25, 2016 at 14:54

2 Answers 2


If you have a suspicion that, such a thing, i.e., a long output, to happen, start your session by executing command


this will log all your screen output as well as what you type in to the terminal (caveat emptor, backspaces and other normally unprintable characters will make the file harder to read, if you are not careful).

when you are done executing your long winded command, just type exit and it will tell you it saved the session output in a file called typescript. Also you can change the name of this file by running your command as

script my_output_file_name

It is a good tool for debugging scripts etc.

  • 1
    Very interesting, but I get this: bash-4.1$ script file file: Permission denied Terminated bash-4.1$
    – altroware
    Commented Jan 25, 2016 at 14:49
  • 1
    OK, as notices by @lese this was due to a folder where I could read but I couldn't write. Thanks!
    – altroware
    Commented Jan 25, 2016 at 15:36
  • 1
    script ~/somefile; # or # script /some/path/you/can/write/to
    – Jeff Schaller
    Commented Jan 25, 2016 at 16:53
  • 2
    This is a useful solution; yet, is there another way to accomplish what the original poster asked if you didn't type script before? Thanks!
    – Ricardo
    Commented Aug 23, 2018 at 22:28
  • It doesn't work in shell/bash script file.
    – Itachi
    Commented Sep 8, 2021 at 4:03

I prefer the solution given here by the author, Karl Wilbur, since it does not require the "pre" steps like running script.

The gist:

  • triple-click the last line
  • hit shift + home
  • shift + click first line //(or any place you want!)//

and you have all the needed output selected.

Another way is to use Edit -> Select All in the Terminal menu. But it's only about the whole output selection.

You must log in to answer this question.

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