是否有一个Linux命令将列出此终端会话的所有可用命令和别名?

就好像你输入“a”,然后按下tab键,不过是针对字母表中的每个字母。 或者运行'alias',但也返回命令。

为什么?我想运行以下命令,看看是否有可用的命令:

ListAllCommands | grep searchstr

当前回答

或者,你可以得到一个方便的命令列表,并附有快速描述(只要该命令有一个手册页,大多数都有):

apropos -s 1 ''

-s 1 returns only "section 1" manpages which are entries for executable programs.

'' is a search for anything. (If you use an asterisk, on my system, bash throws in a search for all the files and folders in your current working directory.)

然后你想怎么吃就怎么吃。

apropos -s 1 '' | grep xdg

收益率:

xdg-desktop-icon (1) - command line tool for (un)installing icons to the desktop
xdg-desktop-menu (1) - command line tool for (un)installing desktop menu items
xdg-email (1)        - command line tool for sending mail using the user's preferred e-mail composer
xdg-icon-resource (1) - command line tool for (un)installing icon resources
xdg-mime (1)         - command line tool for querying information about file type handling and adding descriptions for new file types
xdg-open (1)         - opens a file or URL in the user's preferred application
xdg-screensaver (1)  - command line tool for controlling the screensaver
xdg-settings (1)     - get various settings from the desktop environment
xdg-user-dir (1)     - Find an XDG user dir
xdg-user-dirs-update (1) - Update XDG user dir configuration

结果似乎没有排序,所以如果您正在寻找一个很长的列表,您可以在中间抛出一个|排序|,然后将其输送到一个寻呼机,如less/more/most。阿拉巴马州:

apropos -s 1 '' | sort | grep zip | less

它返回名称或简短描述中包含“zip”的所有命令的排序列表,并将其泵入“less”寻呼机。(你也可以用$PAGER替换“less”并使用默认的寻呼机。)

其他回答

对于Mac用户(find没有-executable, xargs没有-d):

echo $PATH | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm '++x'

问题是选项卡补全正在搜索您的路径,但并非所有命令都在您的路径中。

使用bash查找路径中的命令,你可以这样做:

在echo $PATH | cut -d":" -f1;做ls $x;完成

其他命令在嵌入式系统上对我不起作用,因为它们需要bash或更完整的xargs版本(busybox是有限的)。

以下命令可以在任何类unix系统上运行。

按文件夹列出:

ls $(echo $PATH | tr ':' ' ')

按名称列出所有命令

ls $(echo $PATH | tr ':' ' ') | grep -v '/' | grep . | sort

使用"which searchstr"。返回二进制文件的路径或别名设置(如果它是别名)

编辑: 如果你正在寻找一个别名列表,你可以使用:

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

添加到任何你喜欢的路径搜索答案。假设您正在使用bash..

尝试按ALT-?(alt和问号同时输入)。给它一两秒钟的时间来构建列表。它应该在bash中工作。