Linux command to list all available commands and aliases

前端 未结 20 2304
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 14:11

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

相关标签:
20条回答
  • 2020-11-29 14:47

    There is the

    type -a mycommand
    

    command which lists all aliases and commands in $PATH where mycommand is used. Can be used to check if the command exists in several variants. Other than that... There's probably some script around that parses $PATH and all aliases, but don't know about any such script.

    0 讨论(0)
  • 2020-11-29 14:47

    Use "which searchstr". Returns either the path of the binary or the alias setup if it's an alias

    Edit: If you're looking for a list of aliases, you can use:

    alias -p | cut -d= -f1 | cut -d' ' -f2
    

    Add that in to whichever PATH searching answer you like. Assumes you're using bash..

    0 讨论(0)
  • 2020-11-29 14:49

    It's useful to list the commands based on the keywords associated with the command.

    Use: man -k "your keyword"

    feel free to combine with:| grep "another word"

    for example, to find a text editor: man -k editor | grep text

    0 讨论(0)
  • 2020-11-29 14:52

    The problem is that the tab-completion is searching your path, but all commands are not in your path.

    To find the commands in your path using bash you could do something like :

    for x in echo $PATH | cut -d":" -f1; do ls $x; done

    0 讨论(0)
  • 2020-11-29 14:53

    You can use the bash(1) built-in compgen

    • compgen -c will list all the commands you could run.
    • compgen -a will list all the aliases you could run.
    • compgen -b will list all the built-ins you could run.
    • compgen -k will list all the keywords you could run.
    • compgen -A function will list all the functions you could run.
    • compgen -A function -abck will 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 yout want.

    0 讨论(0)
  • 2020-11-29 14:53

    Try to press ALT-? (alt and question mark at the same time). Give it a second or two to build the list. It should work in bash.

    0 讨论(0)
提交回复
热议问题