Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

In my current zsh behaviour, hitting tab after typing "sudo" just adds a space.

$ sudo ...

What I really want is for the tab to fully expand to the path of the binary it is about to execute when I hit tab, allowing me to see what will be run:

$ /usr/bin/sudo ...

The aim is to protect against the case where the local user on my machine is hacked, an entry added to my $PATH variable, and 'sudo' runs a malicious program, which would be an easy escalation to root.

share|improve this question
There is another solution which does not involve rebinding tab. Prepend the command name with = and press tab after the command, and it will expand the command name into full path. – Mischa Arefiev Feb 22 '13 at 10:46
up vote 5 down vote accepted

Use bindkey builtin command to bind keys to Zsh commands, like this:

bindkey "^I" expand-cmd-path 

where "^I" is Tab. You can just drop this line into your ~/.zshrc file. Warning: it will break autocompletion of arguments.

share|improve this answer
Cheers! Clearly this is not an ideal solution so I've bound it to Ctrl-O instead. However there aren't many binaries that take password inputs (sudo, ssh, gpg, ...), so I'm happy to just hit Ctrl-O whenever I'm using one of those.I should also point out that this doesn't solve the entire problem since anyone with access to my account can subvert it via .zshrc or xmonad.hs, but gets me some of the way there! – Ali Jan 28 '12 at 20:04

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.