Just a short post about how you can keep track of the which commands you have executed as well as there output. This is especially useful when you want to document how you performed some task or solved some problem. So it’s a great tool when you write blog posts about such things !
All you have to do is call the script command and provide a path to a file where the output will be logged e.g.:
From now on, everything will be logged. To stop logging, just type:
The ouput in the file basically looks the output on the terminal but you do not need to worry about the window buffer, about the terminal crashing or you forgetting to copy the contents of the terminal window before closing. An additional benefit of the script command is that it also saves colored output, so if you executed the following:
ls -l --color=always /usr
you would see a colored output when using cat to output the contents of the file:
Of course when using it to write blog posts, one thing which is still missing are changes to files done using vi or nano. But I haven’t yet found a tool for this. One solution would be to have a script calling vi or nano and first saving a copy of the file and making a diff once you exit the editor…
One thought on “Linux: keep track of command execution and its output”
nice tool, thanks for pointing it out.
To keep track of the vi-ed changes, how about using the backup vi saves automatically? My personal habit is to make a copy any time before I touch a file, at least on a productive system or on a deployment candidate, so I can reproduce the changes if needed.
Just my EUR 0.02 ;o)
Thanks for your Articles, keep up posting these gems!