Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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).

share|improve this question

marked as duplicate by Gilles, G-Man, cuonglm, Stephen Kitt, Archemar Aug 3 '15 at 8:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 5 down vote accepted

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

will send everything you see on the screen to the named text file.

share|improve this answer
Thanks you, that's exactly what I was looking for – BCqrstoO Jan 30 '14 at 18:37
Is there a way to avoid the "^M" characters that are appended to the end of each line in the typescript file produced by a script session? Of course, these can be removed easily, but I wonder whether their generation by the script command can be avoided in the first place. Thanks. – user001 Apr 2 '15 at 2:13

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.

share|improve this answer
This is interesting, thanks for this info – BCqrstoO Jan 30 '14 at 19:08

You're looking for script:

     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.

share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.