Is it possible to save the output of a previous command on file?

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.

Tags:

Terminal

Bash