Is there a way to get a list of all commands that match a specific (case insensitive) pattern? So for example, I know the command (which might be an alias) I'm looking for contains "diag" or "Diag" but I'm not sure of the actual command.

I'm currently on Ubuntu with Bash but am asking specifically on this site because I'd love to learn of a way that's usable across various kinds of distros (e.g. I'll need this skill on CentOS and Manjaro later on too).

I've tried man iag hoping it would work the same as Powershell's help iag but that doesn't work.

I've tried my Google-fu but that only seems to lead to explanations on how to find files by partial name of text inside files.

I've tried searching this SE site in various ways (e.g. 1, 2) but didn't find a duplicate of my question.

How do you find the exact name of a command if you can remember only part of it?


Use compgen -c to get a list of all commands, you can also use it like:

compgen -c dif

to get a list of all commands started with "dif".

Combine it with grep to get exactly what you are looking for:

compgen -c | grep -i diag

which looks for any commands containing "diag". use regex for more flexible searches:

compgen -c | grep -i ^diag   # started with diag
compgen -c | grep -i diag$   # ended to diag

You can also use apropos to find commands, it searches into the manual page names and descriptions.

  • Perfect! The first option was what I was asking for, but the second option is equally useful! – Jeroen Jul 23 '17 at 13:05
  • You can use -a for aliases, -k for keywords, etc... – Ravexina Jul 23 '17 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.