We're an ISO27001:2013 Certified Supplier


The script command will record all keystrokes typed in a shell session to a file. Maybe you know about that, but if you’re using script to help with training, there’s some extra functionality that may be helpful.

Firstly, the script command itself. This can be useful when running a long sequence of commands by hand; for example, when carrying out a system upgrade, you may have a set of steps to follow. By using script to record all the keystrokes, in the event that there are problems you have an effective audit log of what was typed:

$ script upgrade_system.script

Now, all commands typed, together with the system prompt, will be recorded in upgrade_system.script.

Tip: because script also records the shell prompt, if your prompt contains escape characters, they too will be written to the file.

You may want to start your script recording as follows:

FancyPrompt $ screen upgrade_system.script
FancyPrompt $ export PS1="$ "

That will reset your prompt just for the duration that you are recording the keystrokes.

To stop recording:

$ exit
Script done, file is upgrade_system.script


If you’re recording keystrokes for future use as a training aid, this may be helpful:

$ script --timing=demo.timing demo.script

If you now run some commands and end with exit, the commands can be replayed with the same timing as follows:

$ scriptreplay -t demo.timing -s demo.script

The rate of playback can be changed; see the scriptreplay(1) man page.

Was this tip helpful?

Let us know in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get free Linux business strategies

Fill in this form and we'll send you updated Linux business strategies and ideas each week
  • This field is for validation purposes and should be left unchanged.