You supposedly can make some sort of low-tech replacement to screencasts of your terminal sessions with script(1):


script makes a typescript of everything displayed 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).

I now created a typescript file. But how do I make a readable pdf from it?

I used lp with the printer PDF from cups-pdf but the output is garbled. There are lots of m, 0; and 34;42 where should be blanks.


A utility that seems to work quite well with handling ansi escapes and input line editing from a typescript is ansi2html.sh which obviously generates html. You can either view this output in your browser and use its printing features, or, if you dont mind losing the colours, convert the html back to simple text with no escapes, eg with

ansi2html.sh <mytypescript | w3m -dump -T text/html >out.txt

You can then use enscript to print simple text files.

  • I think github.com/theZiz/aha works better – wolf-revo-cats Jun 6 '16 at 1:31
  • I found aha didnt handle backspaces in the commands typed in to bash, for example, whereas ansi2html.sh did. So typing abc\b\b\bdef (where \b represents a backspace) showed as abcdef in the former, but def in the latter. – meuh Jun 6 '16 at 4:55

There's two choices:

  • replay the script (with pauses, even via XOFF/XON), and make screenshots which some tool may convert into PDF

  • strip the control sequences from the file, leaving a plain-text file that can be converted into PDF.

Generally I've done the latter; both have their pitfalls. When making screenshots, you may not get exactly the picture you wanted (though using scriptreplay, it's possible to slow things down to make it simpler to pause the screen). Filtering escape sequences works well enough for command-line applications such as "colorized ls", but poorly for screenshots of a text editor.

Further reading:


The counterpart of script(1) is scriptreplay(1):

    This  program  replays  a typescript, using timing 
    information to ensure that output happens at the same 
    speed as it originally appeared when the script was recorded.

Also, scriptreplay provides option to speed up/slow down the replay.

Thus, you can't just print it. You could replay it and capture screenshots or make a movie.

  • How do you know for sure, that one just can't print it? It even says it can be printed in the manpage. – wolf-revo-cats Jun 5 '16 at 5:38
  • Of course it can be printed as any text document with one exception: "Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal." (from the same man page). Did you use vi or alike? I meant exactly your case: you have such garbage in the script – Serge Jun 5 '16 at 5:49
  • Another thing that may produce 'garbage' is colored text output. – Serge Jun 5 '16 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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