--------------------------------------------------- Screen Dumps and Capturing Text via Script or Mouse --------------------------------------------------- -Ian! D. Allen - idallen@idallen.ca - www.idallen.com If you want to capture into a file the text in a Unix/Linux terminal session, perhaps to submit for marking or to email your instructor for assistance with debugging a problem, here's how to do it. Using Script to capture a session --------------------------------- If you are required to save a terminal session, you can use the "script" command to save all terminal input and output into a text file at the same time as it displays in your terminal window. Unix/Linux has a "script" command that will do this; except, it saves *every* character you type, including backspaces and terminal control characters. This can make the resulting output file unreadable. Instead of using the Unix/Linux "script" command, which garbles output, use my "ianscript" version of the command, as given in Step 1 here: 1) Start a script session using the script cover program in my home bin directory. Give an output file name as an argument, e.g. "testing.txt": $ ~idallen/bin/ianscript testing.txt This command will start a subshell (a nested shell). Everything you type from now until you exit the subshell will be saved into the file. The script cover I wrote calls the standard "script" command with some environment options set to minimize escape sequences that clutter the script output file. Make sure you use my "ianscript" command, not the "script" command! For more scripting options, you can read the "man script" page. 2) Perform your terminal session in this new "ianscript" subshell. All your terminal command lines and output, including all your typing mistakes, will go into the given file name. The input and output will appear on your screen and also be saved in the argument file name you gave, e.g. "testing.txt". Note: Your output file "testing.txt" will not contain the full results of your script session until you exit the subshell started by the script command. When you exit the subshell, script will flush the last lines of the session and will tell you the name of the output file. 3) Don't make the mistake of looking at the script output file while you are still running the script session. Doing so makes a real recursive mess of the script file. Exit the subshell before you try to look at the contents of the script output file. 4) While running a script session, realize that *everything* you type and see on your screen will go into the output file. Do *not* use any extra programs, such as editors or man page readers, that will generate hundreds of lines of junk in the script file. Exit the script before you try to edit anything or read man pages. 5) The only lines you should type in the script session are the lines required by the assignment. Do all your editing and man page searches in another window. 6) Exit the script session subshell when you are done your terminal session. Now you can look at the output file. Script will remind you of the name of your script output file when you exit the subshell: $ exit Script done, file is testing.txt $ less testing.txt You may now examine your saved script session, edit it, mail it, etc. Mouse-based copy ---------------- Your instructor may prohibit mouse-based copy for some assignments; since, the text copied is easily mis-formatted. (TAB characters don't show up, multi-byte characters get lost or mis-handled, etc.) Only use the mouse for a cut/paste if you know it's allowed. If the session is small and fits in a (possibly scrolling) terminal window, you can use your mouse to left-click-drag over the text to select it, then start up a separate window and paste (middle mouse button) the text into an editor or into a "cat" command with output redirected to a file, e.g.: $ cat >session.txt If you paste into an editor such as VIM that auto-wraps text, you should turn off auto-wrap and auto-indent before you paste. In VIM use :set paste before you open up in input mode.