OK this is more than I need right now, but I did get curious about the "script" command that captures your term session to a text file- to start and stop use:
script
ctrl-d
But when looking at my output file (if you just do what I did above it will be called 'typescript') it has control characters around the file names. How can I suppress these?
I bet you've got ls set to colorize file names, right? What you're seeing as"control characters around file names" is VT-100 escape codes to colorize the text different ways. If you do command-line editing in Bash (vi or emacs mode) you'll also see all the control characters that implement the editing. Again, more VT-100 escape code to position the cursor, overwrite characters, etc etc.
Either you set ls to not colorize filenames, or you edit the 'typescript' file. One of the values of script is that it doesn't do any interpretation of the characters it records.
You can achieve the some of the same results with less -R and you also get searching and scrolling. (It colorizes ls's output, but it doesn't do the scrolling or screen-clearing stuff.)
To get a handle on why this happens, think of it this way: Back in 1983 using Unix (and I mean a full-size Serious Unix, not Xenix for the 8088 or anything) meant hooking a text terminal (like the brand-new VT-220!) to a minicomputer (like a PDP-11 or a VAX) over a serial line, possibly also involving a modem.
Now you only have one communication channel between your text terminal and the computer. That's a bidirectional link that ships characters at, say, 120 characters per second, a good speed for the time. Given that there is only one channel to work with, if you want to make some text underlined, for example, you have to tell the terminal to do it using in-band signalling. The VT-220 has a complex set of such commands, or control codes, prefixed with the ESC character (0x1b in ASCII). In-band means everything is done using the same line, so there is fundamentally no difference between the characters in the "Hello, world!" your application prints and the control codes that make some of ls's output bold.
And that's it: If an application sends a sequence of characters that's a control code recognized by the terminal, the terminal will interpret it and do something special, like make the following text yellow-on-red and blinking. (The VT-220 might not have been able to do color, but other terminals could, including terminal emulation software for the IBM PC, say.)
The catch is, there was very little standardization about what control codes did what. ANSI tried to standardize, and was successful to the extent the popular VT-100 family followed the standard at least partway, but it was too complex a standard to succeed completely. These days, of course, pretty much everyone uses xterms and they're pretty close to the ANSI standard as well. On the other hand, back when ADM-3As and Wyse 60s roamed the Earth, just about all you could assume was that all of the printable ASCII characters (plus space) would make the appropriate characters on the screen and that CR (0x0d) would be a carriage return.
That lack of standardization is why termcap and terminfo exist: They map 'what the terminal can do' with 'how to do it' in terms of control codes. It's also why curses and ncurses were written (as APIs to abstract 'what' from 'how'), and why terminal handling code has largely been done via an API of some kind for the past three decades or so. ncurses is like Xlib for text terminals, right down to the network transparency.
Here's a page where you can download massive termcap and terminfo files, if you ever need to know how to make an ADM-3A clear its screen: http://www.catb.org/terminfo/
Awesome stuff, derleth. I do remember the days of ctrl-h backspace and ctrl-g ringing a bell. I also remember playing with the escape codes more-- goofy high school ('70s) and college ('80s) tricks. Back in the days of "Creative Computing" (later -> Byte)
Almost forgot: Under xterm, at least, ^V is the escape character and ^[ is ESC, so you can type things like:
$ echo '^[[0m^[[01;32mfoo^[[0m'
with a ^V before every ^[ (the ^V doesn't get echoed back to you unless you type ^V^V to enter a single ^V). That makes 'foo' bold and lime green.
Once you learn how to read a terminfo file, you can do everything your terminal is capable of (and xterm can do quite a bit) entirely by typing control codes by hand. Which is pointless, given that tput, from the ncurses package, does the same thing in a much more user-friendly way that's also completely terminal-independent.