There are times when you need to post the outcome of a particular command(s) from a shell on a forum or somewhere else. It might be for troubleshooting or demonstration. However, copy-paste is not exactly a good option if your shell is filled with tons of information. Not to mention, you would spend a lot of time just selecting the text & then pasting it into a word processor. Wouldn’t life be easy if there would be a script which would gather all the data from a terminal & save it to a file? It does exist.
Before starting to run the command(s) whose output you wish to capture, enter;
$script -a filename
You will get,
[shuttertux@localhost ~]$ script -a filename
Script started, file is filename
[shuttertux@localhost ~]$
Now one can begin entering the required commands. Once done, type;
$exit
You’ll get,
[shuttertux@localhost ~]$ exit
exit
Script done, file is filename
[shuttertux@localhost ~]$
Now you can view the output file simply by,
$cat filename
Wasn’t that easy? Just remember, the output file is saved in your present working directory.