Linux command line FAQ: How can I record the input and output of my Linux command line (i.e., the Linux commands I type, and the output from those commands)?
Today I was installing a product from the command line on a Unix/Linux system, and they asked if I could let them know how the installation went. I said "Yes, I can let you know exactly how it goes", because I knew that I could record my entire command line login session using the Unix/Linux/BSD
The script command is usually a no-brainer to use. When you're ready to start recording the input/output of your login session, just type
at the command line. You'll get a message back from the operating system that looks like this:
Script started, file is typescript
This is the system's way of telling you that it is now recording everything you type, and everything that is displayed on your console. When you're finished recording whatever it is that you want to record, type
exit, and your script session will end. (Make sure you only do an exit command once to exit the script environment, because if you do it twice, the second "exit" command you issue will log you out of your system.)
When you do so, you'll see a message that looks like this:
Script done, file is typescript
If you'll now look at this file named
typescript, you'll see that it contains everything you typed, and everything that the system printed out, as promised. Depending on what you do at the command line it may also contain a bunch of control characters, but those are easily weeded out so you can get back to plain ASCII text. I'll show how to do that in another blog entry.
Note that the script command should be available for recording your login session on most Unix systems, including vanilla Unix, Linux, BSD/freeBSD, Solaris, AIX, and others.
I hope this tip on using the Unix/Linux script command to record your command line input and output has been helpful. As mentioned, I find it to be a very good way to document the Linux commands I type.