Linux command to list all available commands and aliases

前端 未结 20 2303
佛祖请我去吃肉
佛祖请我去吃肉 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:40

    Here's a function you can put in your bashrc file:

    function command-search
    {
       oldIFS=${IFS}
       IFS=":"
    
       for p in ${PATH}
       do
          ls $p | grep $1
       done
    
       export IFS=${oldIFS}
    }
    

    Example usage:

    $ command-search gnome
    gnome-audio-profiles-properties*
    gnome-eject@
    gnome-keyring*
    gnome-keyring-daemon*
    gnome-mount*
    gnome-open*
    gnome-sound-recorder*
    gnome-text-editor@
    gnome-umount@
    gnome-volume-control*
    polkit-gnome-authorization*
    vim.gnome*
    $
    

    FYI: IFS is a variable that bash uses to split strings.

    Certainly there could be some better ways to do this.

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

    in debian: ls /bin/ | grep "whatImSearchingFor"

    0 讨论(0)
  • 2020-11-29 14:42
    compgen -c > list.txt && wc list.txt
    
    0 讨论(0)
  • 2020-11-29 14:43

    You can always to the following:

    1. Hold the $PATH environment variable value.
    2. Split by ":"
    3. For earch entry: 
        ls * $entry 
    4. grep your command in that output.
    

    The shell will execute command only if they are listed in the path env var anyway.

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

    Why don't you just type:

    seachstr
    

    In the terminal.

    The shell will say somehing like

    seacrhstr: command not found 
    

    EDIT:

    Ok, I take the downvote, because the answer is stupid, I just want to know: What's wrong with this answer!!! The asker said:

    and see if a command is available.

    Typing the command will tell you if it is available!.

    Probably he/she meant "with out executing the command" or "to include it in a script" but I cannot read his mind ( is not that I can't regularly it is just that he's wearing a mind reading deflector )

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

    For Mac users (find doesn't have -executable and xargs doesn't have -d):

    echo $PATH | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm '++x'
    
    0 讨论(0)
提交回复
热议问题