Linux has many useful built-int tools. compgen command is one of those lesser known but very useful Linux command. Ever wanted to list all the Linux commands (including bash shell aliases and functions) you could run on the server / workstation? Try compgen command. compgen is bash built-in command and it will show all available commands, aliases, and functions for you. The syntax of this command is very simple.
Learn more about useful Linux command line utilities: Linux Commands Cheat Sheet for Beginners and Advance Users
compgen [option] [word]
Working with compgen command in Linux
To list all commands that are available to be directly executed.
You can also make use of well know Linux utility grep to find the commands with specific keywords
compgen -c | grep gnome
To list all the bash aliases
To list all the bash built-ins
To list all the bash keywords
-A action = The action may be one of the following to generate a list of possible completions.
compgen -A function
-C command = Run command in a subshell and use its output as the list of completions.
-F function = Run shell function in the current shell. Upon its return, retrieve the list of completions from the COMPREPLY array.
-G globpat = The filename expansion pattern globpat is expanded to generate the possible completions.
-P prefix = prefix is added at the beginning of each possible completion after all other options have been applied.
-S suffix = suffix is appended to each possible completion after all other options have been applied.
-W wordlist = The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members of the resultant list which match the word being completed.
-X filterpat = filterpat is a pattern as used for filename expansion. It is applied to the list of possible completions generated by the preceding options and arguments, and each completion matching filterpat is removed from the list. A leading ‘!’ in filterpat negates the pattern; in this case, any completion not matching filterpat is removed.