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

It should be possible to do that by having ALT+UP generate consecutive keyboard input equivalent to cdspace..ENTER by means of a macro definition. But can't figure out how exactly to do it.

share|improve this question
up vote 13 down vote accepted

To do literally what you're asking, put the following line in your ~/.inputrc:

"\e\e[A": "cd ..\n"

Here \e\e[A is byte sequence that your terminal sends when you press Alt+Up (\e is parsed as the escape character), some terminals might send \e[1;3A~ or some other sequence instead. To find out what sequence your terminal sends, run cat and press the key (escape will display as ^[).

In bash, you can in principle bind a key to shell code, so in theory this should work:

bind -x '"\e\e[A":cd ..'

However as of bash 4.2 it doesn't work due to a hard-to-fix implementation bug. Zsh expert Stéphane Chazelas has a workaround:

bind -x '"\201":cd ..'
bind '"\e\e[A":"\201"'

The effect is somewhat confusing because the prompt isn't redrawn.

In bash ≥4, add shopt -s autocd to your ~/.bashrc. Then you can change to the parent directory (or any directory) by entering just .., without having to type the cd command.

share|improve this answer
This looks like a super-high quality answer, but for some reason it is not working in a Git Bash shell on Windows. (Haven't pulled out my Air to test there though yet...) Are you aware of any gotchas that uniquely affect Cygwin? – iconoclast Jul 25 '12 at 19:55
(I should have mentioned that it closes the terminal window.) – iconoclast Jul 25 '12 at 20:54
for some reason SE removed "@Gilles:" from the beginning of my comments. WTF!? – iconoclast Jul 26 '12 at 22:20
@iconoclast I think both Console2 and Mintty are portable. For Console2, unpack the zip and run it. For Mintty, you need mintty.exe plus the Cygwin dll either in the same directory or elsewhere on the %PATH%. Regarding the stripping of @Gilles: Eeeeek - what happened to my @ salutation? – Gilles Jul 26 '12 at 22:35
@iconoclast I think the founder and then lead developer (not a UX person) forced this feature through. Don't blame the UX designer for this. – Gilles Jul 26 '12 at 23:35

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.