Ask Different is a question and answer site for power users of Apple hardware and software. 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

In a Terminal, if I type beginning of any command by pressing tab I can see the rest of that command.

However this feature does not work with any words I type after sudo.

How can I complete command names even after I write sudo?

share|improve this question
One way would be to write the command first, followed by Ctrl-A to jump to the beginning of the line and then type sudo. – patrix Feb 15 '13 at 20:50
up vote 10 down vote accepted

OS X has not turned ON as many completion possibilities at the guys behind Ubuntu. In order to add autocompletion to sudo, you should simply add to the file $HOME/.bash_profile

complete -cf sudo

The description of complete and its options is briefly defined in the bash built-in commands manual page (see man bash). Although the -c and -f commands are not obviously detailed, one can find their description under the "-A action" explanation.

share|improve this answer

I did fix my problem by installing Bash Completion on Macports.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

It would help to know what shell you are using. This works for me in both bash and zsh. The completion in zsh is much better than bash.

One thing you could do is to type the command you want using tab completion, but before hitting return type control-a to go to the beginning of the line and then type sudo and hit return to execute the command.

share|improve this answer
I checked terminal -> preferences it says Login Shell. I think I'm not using any special shell. actually I wrote /bin/bash and /bin/zsh none of them helped to fix my problem. – Rodrane Feb 15 '13 at 21:17
Do what I recommend in the second paragraph of my answer. That is best. – Mark Feb 15 '13 at 21:24
yeah but I wanna use it like as I always did in ubuntu is there any other way to do that ? – Rodrane Feb 15 '13 at 21:26

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.