In Unix and ASCII, bytes 1 through 26 are control-A through control-Z. But there are control characters outside that range: 0, 27 through 31, and 127. As a result of writing up my _.screenrc I've become curious about what all of them are, so here's my handy chart:
| 0 | Ctrl-@ | also Ctrl-`, Ctrl-space, Ctrl-2 in
xterm
|
| 27 | ESC, Ctrl-[ | also Ctrl-5 in
xterm
|
| 28 | Ctrl-\ | also Ctrl-4 in
xterm
|
| 29 | Ctrl-] | also Ctrl-3 in
xterm
|
| 30 | Ctrl-^ | also Ctrl-~, Ctrl-6 in
xterm
|
| 31 | Ctrl-_ | also Ctrl-/, Ctrl-7 in
xterm
|
| 127 | DEL, Ctrl-? | also Ctrl-8 in
xterm
|
The canonical representation of a control character is based on what Unix prints it as when you enter it (usually with Ctrl-V followed by the character, however you generated it). It turns out that
xterm
will generate a number of these sequences with alternate Ctrl combinations as noted in the chart (which is probably not complete). Some of these
xterm
alternates may be more convenient under some circumstances.
Your mileage on actual serial terminals and other terminal emulators may vary, although
gnome-terminal
and
urxvt
match up for the primary control sequences and at least some of
xterm
's alternate ways of generating them. Historically serial terminals could be very variable outside Ctrl-A through Ctrl-Z.
Backspace traditionally sends Ctrl-H. Ctrl-\ is traditionally what
stty
will report as 'quit', ie it sends SIGQUIT ('please die down with a core dump') to programs; this can make it kind of hard to work out just what ASCII code it represents. I resorted to entering it in
vi
, saving the file, and then using
od
to dump the file.
In case you ever need to know this, Ctrl-J is the real end of line character in terminal entry, aka
\n
; the tty driver maps Return (aka Ctrl-M aka
\r
) to it normally, but this can be disabled and then you can be stuck if, eg, you crashed a program that uses 'raw mode' when you were trying to work out the ASCII number for Ctrl-\. Many but not all shells will accept Return (or a literal Ctrl-M) as a synonym even in this situation, so you can type commands, but any actual command that prompts you for something probably won't.
(The specific tty mode flag this is controlled by is
ICRNL
, per CBreakAndRaw . It follows that '
stty icrnl
' will help restore a broken session, although you might as well go all the way to '
stty
sane
'.)
Sidebar: the odd case of
konsole
Konsole works just like
xterm
with the sole exception that Ctrl-? does not seem to generate a Ctrl-? (it can be generated with Ctrl-8, though). Instead konsole appears to swallow Ctrl-? outright, which may have something to do with some sort of magic DEL handling it's doing.