列出所有可用命令和别名的 Linux 命令 [英] Linux command to list all available commands and aliases

查看:19
本文介绍了列出所有可用命令和别名的 Linux 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a Linux command that will list all available commands and aliases for this terminal session?

就好像您输入了a"并按下了 Tab 键,但是对于字母表中的每个字母.或者运行别名"但也返回命令.

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

推荐答案

您可以使用 bash(1) 内置的 compgen

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

  • compgen -c 将列出您可以运行的所有命令.
  • compgen -a 将列出您可以运行的所有别名.
  • compgen -b 将列出您可以运行的所有内置程序.
  • compgen -k 将列出您可以运行的所有关键字.
  • compgen -A function 将列出您可以运行的所有函数.
  • compgen -A function -abck 会一次性列出以上所有内容.
  • 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.

直接回答您的问题:

compgen -ac | grep searchstr

应该做你想做的.

这篇关于列出所有可用命令和别名的 Linux 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆