• Main Menu
  • How to Capture a Unix Terminal Session


    One of the best methods to capture a Unix terminal session is to use the `script` command.

    In this example we start a script session, run a couple of commands, and then use the `exit` command to stop capturing the terminal session:

    $ script
    Script started, output file is typescript
    $ pwd
    /home/will
    $ ps
     PID TT STAT TIME COMMAND
    11909 p0 Ss 0:00.05 -bash (bash)
    25622 p0 S+ 0:00.01 script
    25623 p1 Ss 0:00.01 /usr/local/bin/bash -i
    25624 p1 R+ 0:00.00 ps
    $ exit
    Script done, output file is typescript
    

    We have now captured our terminal session into the file "typescript".

    We can use the `cat` command to view the contents of the "typescript" file:How to Capture a Unix Terminal Session

    $ cat typescript
    Script started on Tue Jul 26 21:28:50 2005
    $ pwd
    /home/will
    $ ps
     PID TT STAT TIME COMMAND
    11909 p0 Ss 0:00.05 -bash (bash)
    25622 p0 S+ 0:00.01 script
    25623 p1 Ss 0:00.01 /usr/local/bin/bash -i
    25624 p1 R+ 0:00.00 ps
    $ exit
    Script done on Tue Jul 26 21:29:13 2005
    
    • MrBCut

      Thank you so much! Compact, clear and concise! I learned. :)

    • Raj

      Thank you exactly what I was looking for

    • Dipish

      What is the best way to view the recorded session file? If I have color terminal, there are lots of control characters in the typescript file. Is there a viewer for them, besides the console cat and more?

    Unix
    292 queries in 0.807 seconds.