I do not know if this is even possible or not, but in an attempt to keep track of many changes I am about to make to my system I want to track all input I type and all output from a terminal I’m working with to a file. I’ve been messing around trying to do this and here is what I have so far:
bash > /tmp/output.txt
This has some quasi success. I tested this with something simple: sudo apt-get update && sudo apt-get upgrade which dumped the normal output to the file, but not what I typed in.
Additionally I’d like to be able to see the output as well as have it stream to my output file, just for readability. (This can be worked around with a second terminal running tail -f, but it’d be nice to have it in one place).
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use the Script Command
You probably want the /usr/bin/script command. It creates a typescript of your current terminal session. It won’t work very well with curses-based applications, but works very well for creating a typescript.
For example:
script ~/terminal_session.txt echo foo echo bar > /dev/stderr exit
will send everything you see on the screen to the named text file.
Method 2
For a precise recording of a text session, including timing, without messing up full-screen applications, you can use ttyrec.
For interactive applications where text scrolls by, you can use the script command.
Method 3
You’re looking for script:
DESCRIPTION
script makes a typescript of everything printed on your terminal. It is
useful for students who need a hardcopy record of an interactive session
as proof of an assignment, as the typescript file can be printed out
later with lpr(1).
If the argument file is given, script saves all dialogue in file. If no
file name is given, the typescript is saved in the file typescript.
This should be installed by default on most Linux systems since it is part of the util-linux package. To use it, just start a your shell like this:
script session.log
Now, go about your business as usual, it should be completely transparet to you. When you’re done, hit Ctrl + D or run exit. That will save everything you did into session.log.
Method 4
I don’t think you can do exactly what you’re asking for.
However, if you want a record of what you’ve done the script command is probably what you want. It records all typed-in input and all output to a file. It’s a text file, usually named “typescript”. You will find it in the directory in which you started script.
script is part of the util-linux package under Arch linux.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0