Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

After googling for some Mac OS X terminal shortcuts, I wanted to find how can I go back characters on a line on the terminal or words or similar. I found ALT + B but it does not work.

Do you know some other shortcuts, or how can I customize them or links to cheat sheets?

share|improve this question
duplicate: superuser.com/questions/113103/… ... not OSX specific but does provide a lot of information about standard bash keyboard mappings, customizing readline, and other fun bash tricks. –  quack quixote Mar 26 '10 at 17:35
this is not a duplicate of the above question. this one is about how to get OSX not to catch key bindings that are bound for the terminal –  Arthur Ulfeldt May 13 '10 at 18:57
Please unmark this as duplicate. It needs an answer indicating 'use option as meta key' for OSX terminal. –  bentford Nov 8 '10 at 21:24

5 Answers 5

up vote 4 down vote accepted

One way to deal with 'meta' key sequences not working on the OS X terminal is to assign specific character sequences to particular keypresses. For those of us with non-US keyboards, this is often a better solution than the "Use option as meta" setting mentioned in the comments of other answers. (Many international Mac keyboards are essentially unusable for development work without the Option/alt key because certain critical characters are otherwise unavailable. There's no # on a UK Mac keyboard, for example.)

To get word-left and word-right working for bash, I've used the "Keyboard" section of the Settings in Terminal. You can tell it to generate particular code sequences when particular keypresses are made. I've got mine configured so that option cursor left generates \033b (that's actually two characters: Esc, and then a lowercase b) and option cursor right generates \033f (i.e., Esc f). This lets you use the arrow keys with the option key held down to get the word left and right behaviour.

What I've not yet worked out is how to get the Esc key to work - in theory you should be able to use that for 'meta' sequences but it appears not to work. (So just typing Esc b should go back one word.)

If you have a US keyboard layout, or some other keyboard in which Apple have seen fit to provide all the keys you actually need, then as others have suggested, "Use option as meta key" (also on the Keyboard section of Terminal's settings) is probably a better choice because you'll be able to get to any meta key combination. With that switched on, Alt b works as expected.

share|improve this answer
brilliant, thanks! –  Ricardo Saporta Oct 27 '13 at 18:18

There's really no need to map the option key to meta, in an OS X Terminal, option+left-arrow, option+right-arrow replaces Alt+F and Alt+B respectively. Other commonly used shortcuts all work as implemented on other platforms. esc can emulate the original functionality of the Alt key, but it can be a bit uncomfortable using esc as a modifier, plus you can't hold esc and repeatedly press B or F, you need to let it up and push it back down again each time.


option+left-arrow = back one word

option+right-arrow = forward one word

share|improve this answer

On my UK mac, ALT + cursor left/right goes back/forward one word. Absolutely essential.

share|improve this answer

Mac OS X's terminal is BASH, here's some BASH shortcuts:

Ctrl + A    Go to the beginning of the line you are currently typing on
Ctrl + E    Go to the end of the line you are currently typing on
Ctrl + L    Clears the Screen, similar to the clear command
Ctrl + U    Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H    Same as backspace
Ctrl + R    Let’s you search through previously used commands
Ctrl + C    Kill whatever you are running
Ctrl + D    Exit the current shell
Ctrl + Z    Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W    Delete the word before the cursor
Ctrl + K    Clear the line after the cursor
Ctrl + T    Swap the last two characters before the cursor
Esc + T  Swap the last two words before the cursor
Alt + F  Move cursor forward one word on the current line
Alt + B  Move cursor backward one word on the current line
Tab      Auto-complete files and folder names

The one you are looking for is Ctrl + H. (This is the same as hitting the backspace key)

If you are looking for an escape character to go back one character, you are looking for \b. As in:

$ echo -e "one two\b\b\b\b three" # Will echo "one three"
share|improve this answer
To get the “Alt” bindings to work, the user will have to enable “Use option as meta” in Terminal. This will replace the usual Option-based extended characters and dead keys. –  Chris Johnsen Mar 26 '10 at 15:54
Sidenote: Using alt as meta key makes many needed characters like @[]|{} unaccessible on many international keyboard layouts like german or austrian. You can jump forward or backwards a word by pressing ESC-f and ESC-b respectively. For single characters you can use the arrow keys in most cases. In Terminal.app: Preferences > Settings [Advanced] you can tick a box to "Delete sends Ctrl-H" to have your delete key behave correctly in apps like vim. –  MacLemon Mar 26 '10 at 18:51
-1 This does not answer the question. Chris Johnsen answered correctly, but in a comment. –  bentford Nov 8 '10 at 21:22
The alt commands doesnt work for me Alt + F, and Alt + B doesnt work. I am running bash –  Shervin Oct 20 '11 at 11:23

You want the READLINE section of the bash(1) man page:

man 1 bash
share|improve this answer

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.