DEV Community

rderik
rderik

Posted on

Record your terminal session using the `script`command.

I've been in the situation where I ran a script that behaved weirdly and would love to be able to "replay" what I did to figure out what went wrong. A useful command for those cases is script(1).

The script command (introduced in 1979) allows you to record a terminal session to a file. You can later check and reference that file to analyse it as you please. Or maybe record your terminal as a demo.

As with any other Unix command, the power comes from your creativity on how to use it. You can use script to:

  • Record a demo.
  • Capture output.
  • Record session to report a bug.

You can try it just by typing script in your terminal. It opens up a new shell that will be recorded. By default, the session is saved in a file named typescript.

$ script
% ls
% exit
Enter fullscreen mode Exit fullscreen mode

You can then view the capture by using cat(1):

$ cat typescript
Enter fullscreen mode Exit fullscreen mode

If you are interested in more detail, here are my notes on how to use it:

https://rderik.com/notes/using-the-script-command-to-record-a-terminal-session/

Top comments (2)

Collapse
 
lbonanomi profile image
lbonanomi

I really dig script. Ever want to push scriptfiles to github?

Collapse
 
rderik profile image
rderik

That's an interesting use of Gists, thanks for sharing!