• 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
    

    Got Something To Say:

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

    4 comments
    1. Hank Barta

      11 June, 2018 at 1:23 pm

      Doesn’t record anything on Debian Stretch. The unfortunate choice of a name makes it just about impossible to search for a fix.

      Reply
    2. Dipish

      28 February, 2013 at 8:29 am

      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?

      Reply
    3. Raj

      24 April, 2012 at 5:34 pm

      Thank you exactly what I was looking for

      Reply
    4. MrBCut

      18 January, 2012 at 10:40 pm

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

      Reply
    Unix
    177 queries in 0.510 seconds.