Super User is a question and answer site for computer enthusiasts and power users. 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

Is there a nice way to print (e.g. to stdout) a list of all possible completions of a command in bash (the ones it would give me if I typed the command, then pressed tab)?

Edit: I guess this wasn't really clear, now that I read it again. I know how to get completions manually. I want to do it programmatically.

share|improve this question
up vote 3 down vote accepted

bash does not have a function to do exactly that. The programmable completions depend heavily on various parameters such as the cursor position...

eval $(complete -p 'git' | sed s/^complete/compgen/)

seems to work, but is very fragile.

share|improve this answer
This isn't quite exactly what I wanted, but I guess it's probably as close as I'll get. – Ben Kraft Aug 21 '11 at 15:39

Press TAB twice. Most BASH-like shells will list all matching auto-completion options for a given substring.


root@host$apt-get up

pressing TAB twice on this command will list both Update and Upgrade

share|improve this answer

Make sure you have the bash-completion package installed. Depending on your install type it may or may not be included by default, if not just grab it with yum or apt. After installing, you'll need to log out and log back in or re-source your .bashrc to use it.

@Amazed is spot on as for how to use it.

share|improve this answer

Not really... remember that the completions can be a function and can be dependent on previous arguments.

That said, complete | grep ... might get you someplace

share|improve this answer

I think what you're asking for is basically a list of all the commands beginning with a given string. You should be able to do that by getting a list of all the executables on your system and running them through grep.

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.