Linux command to list all available commands and aliases
·
Answer a question
Is there a Linux command that will list all available commands and aliases for this terminal session?
As if you typed 'a' and pressed tab, but for every letter of the alphabet. Or running 'alias' but also returning commands.
Why? I'd like to run the following and see if a command is available:
ListAllCommands | grep searchstr
Answers
You can use the bash(1) built-in compgen
compgen -cwill list all the commands you could run.compgen -awill list all the aliases you could run.compgen -bwill list all the built-ins you could run.compgen -kwill list all the keywords you could run.compgen -A functionwill list all the functions you could run.compgen -A function -abckwill list all the above in one go.
Check the man page for other completions you can generate.
To directly answer your question:
compgen -ac | grep searchstr
should do what you want.
更多推荐




所有评论(0)