Having more and more Linux machines that I seem to be encountering and administering, there have been a number of occassions where I’ve been stymied by not having a bash command that I was expecting to be available. I wanted a way to see all available commands within bash. A search revealed that many people had many different ways of achieving that goal. Many of them were rather convoluted and required not insignificant shell scripts. However one solution stood out above the others.
Thanks to a user over at StackOverflow, I was introduced compgen. Allow me to introduce you. Compgen is a bash builtin that, in the words of bash’s man page:
compgen [option] [word]
Generate[s] possible completion matches for word according to the options, which may be any option accepted by the complete builtin
And what options does the complete builtin accept? Quite a few. the ones that are most pertinent to me are the -c and -a options. Compgen run with the -c option will show all commands available and the -a option shows all aliases. Piping the results to grep make searching for a command a breeze. Recently I needed to see which filesytem tools were available on a machine so I simply used compgen -c | grep fsck
Now when you’re sitting at a new Linux machine and want to know if you have any commands of a certain type, your just a one-line away from finding out. Do you have any different methods? Let me know in the comments.









About the Author
I am a self employed Systems Administrator in sunny Phoenix, Arizona. I like origami and lemons. I do not like hangnails or snow. Interested in hiring me? Check the blog sidebar to the right for a contact form or email me at [email protected]