Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

When I press tab in a console I get this output

Display all 2957 possibilities? (y or n)

Is there any way to use grep on these 2957 possibilities? I would like to search for all commands with the word "svn" in them.

share|improve this question
up vote 15 down vote accepted

The solution is the bash builtin compgen. To grep 'svn' from all available commands and command aliases accessible through $PATH, type.

compgen -ac | grep svn

Want to search from a certain prefix (eg all commands that start with ecrypt)? Use regular expressions..

compgen -ac | grep "^ecrypt"
share|improve this answer
excellent answer, but what if one wants to grep tab completion possibilities themselves? I mean, it's not always triggered by the command name, but also by command parameters, etc. – UncleZeiv Jan 3 '12 at 14:08

You can try using compgen.

For example:

compgen -ac | grep "svn"
share|improve this answer

This should be equivallent:

for x in `echo $PATH | sed 's/:/ /g'`; do ls $x | grep svn; done
share|improve this answer
for i in $(echo $PATH | tr ":" "\n"); do find $i -type f -perm +111; done | grep svn

Very similar to totaam's answer apart from this limits its scope to executables (as Bash does). But JJE's compgen is another mile better.

share|improve this answer

maybe {,.}*svn* helps here, e.g. ls -l /usr/bin/{,.}*svn*<tab>.

But, have a look on the Zsh! Here: are some great examples how it can help to reduce your tab completion results. This includes also negation, e.g. if you want all tab-completion results without the word "foobar", or all results with even digits in the first place, subdirectory tab-completion and much more. The reason why I changed to zsh was history sharing between all open terminals.

share|improve this answer

I didn't knew compgen, and would have suggested:

ls -d ${PATH//:/\/*svn* } 2>/dev/null

for bash.

${VAR//pattern/replace} replaces in VAR pattern with replace. // is used to replace every pattern, not just the first, which would be just /.
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.