Linux command to list all available commands and aliases

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

    Here's a solution that gives you a list of all executables and aliases. It's also portable to systems without xargs -d (e.g. Mac OS X), and properly handles paths with spaces in them.

    #!/bin/bash
    (echo -n $PATH | tr : '\0' | xargs -0 -n 1 ls; alias | sed 's/alias \([^=]*\)=.*/\1/') | sort -u | grep "$@"
    

    Usage: myscript.sh [grep-options] pattern, e.g. to find all commands that begin with ls, case-insensitive, do:

    myscript -i ^ls
    

提交回复
热议问题