Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example:


I only know bits and pieces, like \e stands for escape and C- for Ctrl, but what are these numbers (1) and letters (Z)? What are the ;, [ and - signs for?

Is there only trial and error, or is there a complete list of bash key codes and an explanation of their syntax?

share|improve this question
An additional tip for listing the actual readline bindings of the shell is bind -p. – user13742 May 21 '13 at 11:27
Most such codes are interpreted by your terminal; read about ANSI escape codes on Wikipedia for a large listing. – chepner May 21 '13 at 14:07
stty -a displays the terminal's line settings – bug May 22 '13 at 14:04
up vote 24 down vote accepted

Those are sequences of characters sent by your terminal when you press a given key. Nothing to do with bash or readline per se, but you'll want to know what sequence of characters a given key or key combination sends if you want to configure readline to do something upon a given key press.

When you press the A key, generally terminals send the a (0x61) character. If you press <Ctrl-I> or <Tab>, then generally send the ^I character also known as TAB or \t (0x9). Most of the function and navigation keys generally send a sequence of characters that starts with the ^[ (control-[), also known as ESC or \e (0x1b, 033 octal), but the exact sequence varies from terminal to terminal.

The best way to find out what a key or key combination sends for your terminal, is run sed -n l and to type it followed by Enter on the keyboard. Then you'll see something like:

$ sed -n l

The first line is caused by the local terminal echo done by the terminal device (it may not be reliable as terminal device settings would affect it).

The second line is output by sed. The $ is not to be included, it's only to show you where the end of the line is.

Above that means that Ctrl-Up (which I've pressed) send the 6 characters ESC, [, 1, ;, 5 and A (0x1b 0x5b 0x31 0x3b 0x35 0x41)

The terminfo database records a number of sequences for a number of common keys for a number of terminals (based on $TERM value).

For instance:

TERM=rxvt tput kdch1 | sed -n l

Would tell you what escape sequence is send by rxvt upon pressing the Delete key.

You can look up what key corresponds to a given sequence with your current terminal with infocmp (here assuming ncurses infocmp):

$ infocmp -L1 | grep -F '=\E[Z'

Key combinations like Ctrl-Up don't have corresponding entries in the terminfo database, so to find out what they send, either read the source or documentation for the corresponding terminal or try it out with the sed -n l method descrive above.

share|improve this answer
This is a great explanation, thanks! Now it all falls into place, \e-1\C-i is a backwards tab, because control and i inserts a tab and escape followed by -1 says bash to do it backwards once (I goggled this and found some stuff about digit-arguments). – bug May 22 '13 at 10:03
$ sed -n 1 sed: -e expression #1, char 1: missing command – Vibhav Sinha Jul 5 '15 at 22:23
@vib. That's lowercase L not digit 1 – Stéphane Chazelas Jul 6 '15 at 7:39
@user367890, that's down to the keypad mode. You'll probably find that after tput smkx, your terminal sends \e[OD (kcub1) and after tput rmkx, \e[D (cub1, the same code as the sequence that moves the cursor to the left, so that the echo of those keys does move the cursor. Try stty -echoctl; tput rmkx; sleep inf and you'll see the arrow keys do move the cursor when not in keypad mode). – Stéphane Chazelas Jul 15 at 7:46
@user367890, from what Thomas (the ncurses and xterm maintainer) says in the answer you link, yes, it should work. keypad mode or application mode refer to the same thing, so (again, according to Thomas) the key specifications in the terminfo database are for when smkx is enabled. – Stéphane Chazelas Jul 16 at 6:31

It is provided via gnu readline library. you should look into man 3 readline to find out its description.

Looks like you also need information about what does escspe codes liks \[A mean. You can find this information in wikipedia ANSI esacape code article.

share|improve this answer
This does not explain my examples. – bug May 21 '13 at 12:40
Looks like it was small misunderstood. Please look at the answer update. – rush May 21 '13 at 13:39
There is no information about my specific examples in the article. A page-search for "[A" returned nothing as well. – bug May 21 '13 at 13:42
@bug please read carefully the article. \[A is in the table "CSI codes" within row: "CSI n A" – rush May 21 '13 at 13:44
Thanks rush, but where do I find explanations on [Z, [1;5C, or -1 ? – bug May 22 '13 at 9:28

Do these codes come from the same source? The last one looks like a GNU readline binding. That's what the user sends to a bash (see rush's answer). The first two, however, look more like terminal control sequences (even though the first one would be an ill-formed one). That's what bash or another program send back to the terminal emulator in order to control cursor movements, text colors, and the like.

share|improve this answer
I found "\e[1;5C" to be used for ctrl-arrow forward word movement, and "\e[Z" and "\e-1\C-i" for menu-complete-backwards in other tutorials. They have all been used inside the .inputrc file. – bug May 21 '13 at 12:37
OK, if they are interpreted by readline then there must be some terminal emulator where these control sequences are bound to some combination of ctrl, alt, and/or shift with function or arrow keys. (I don't know which one.) – Uwe May 21 '13 at 13:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.