4

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?

Al.

PS: for example, I give

diff folder1 folder2 #the folders contain many files

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

  • which terminal emulator do you use? – lese Jan 25 '16 at 14:31
  • @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 Jan 25 '16 at 14:39
  • do you need root proviledges to change the gnome terminal configuration? I don't think so : ) – lese Jan 25 '16 at 14:44
  • @lese Perhaps I should say I don't know how... :-$ – altroware Jan 25 '16 at 14:47
  • @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 Jan 25 '16 at 14:54
3

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

script

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.

  • Very interesting, but I get this: bash-4.1$ script file file: Permission denied Terminated bash-4.1$ – altroware Jan 25 '16 at 14:49
  • OK, as notices by @lese this was due to a folder where I could read but I couldn't write. Thanks! – altroware Jan 25 '16 at 15:36
  • script ~/somefile; # or # script /some/path/you/can/write/to – Jeff Schaller Jan 25 '16 at 16:53
  • 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 Aug 23 '18 at 22:28

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.