Live data from Hacker News

Util-linux cheat sheet

catonmat.net

1–10 of 17 posts

Re: Util-linux cheat sheet

#2
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?

Re: Util-linux cheat sheet

#3
post #2

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.

Re: Util-linux cheat sheet

#4
post #2

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?

Which control characters?

And you say around file names... did you run "ls" while in your script session? if you generated colorized output, script will record that.

If you don't want colorized output, run "\ls" (bypass any alias you might have for ls, and just run ls directly) or use "ls --color=never".

You'll still see ^M at the end of each line.

You can run "dos2unix typescript" to strip those out.

It's script's job to record your entire session, including any control characters, and it does that.

Re: Util-linux cheat sheet

#5
post #2

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?

cat the file.

Re: Util-linux cheat sheet

#6
post #2

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 color…

You are correct- that is exactly what it is. Thanks.

Re: Util-linux cheat sheet

#7
post #4
post #2

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?

Which control characters? And you say around file names... did you run "ls" while in your script session? if you generated colorized output, script will record that. If you don't want colorized output, run "\ls" (bypass any alias you might have for ls, and just run ls directly) or use "ls --color=never". You'll still see ^M at the end of each line. You can run "dos2unix typescript" to strip those out. It's script's j…

You are exactly right. Thank you.

Re: Util-linux cheat sheet

#8
post #2

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?

cat the file.

Interesting- the control characters get re-interpreted into screen commands. Thanks for that.

Re: Util-linux cheat sheet

#9
post #8

Earlier quoted context omitted.

cat the file.

Interesting- the control characters get re-interpreted into screen commands. Thanks for that.

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 an interesting article on modem speeds because it's Saturday: http://www.textfiles.com/computers/bitsbaud.txt

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/

Re: Util-linux cheat sheet

#10
post #2

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?

Haven't looked at the cheat sheets but...

If you just want something readable, a couple of quick and dirty ways are:

    col -bx 
You can further clean things up by deleting unwanted lines or characters using sed.

    strings typescript|sed '1d;/deleteme/d;s/deleteme//g'|less
There's also an old utility called ttyrec/ttyplay you might like.
Post reply on HN