是否有一个Linux命令将列出此终端会话的所有可用命令和别名?
就好像你输入“a”,然后按下tab键,不过是针对字母表中的每个字母。 或者运行'alias',但也返回命令。
为什么?我想运行以下命令,看看是否有可用的命令:
ListAllCommands | grep searchstr
是否有一个Linux命令将列出此终端会话的所有可用命令和别名?
就好像你输入“a”,然后按下tab键,不过是针对字母表中的每个字母。 或者运行'alias',但也返回命令。
为什么?我想运行以下命令,看看是否有可用的命令:
ListAllCommands | grep searchstr
当前回答
问题是选项卡补全正在搜索您的路径,但并非所有命令都在您的路径中。
使用bash查找路径中的命令,你可以这样做:
在echo $PATH | cut -d":" -f1;做ls $x;完成
其他回答
你为什么不直接输入:
seachstr
在终点站。
外壳会说
seacrhstr: command not found
编辑:
好吧,我投反对票,因为这个答案很愚蠢,我只是想知道:这个答案有什么问题!!提问者说:
并查看是否有命令可用。
输入命令将告诉您该命令是否可用!
可能他/她的意思是“不执行命令”或“将其包含在脚本中”,但我无法读懂他的想法(并不是我不能经常读懂,只是他穿着一件 读心术偏转器)
这就是
type -a mycommand
命令列出了mycommand在$PATH中使用的所有别名和命令。可用于检查该命令是否存在多个变体。除此之外……可能有一些脚本解析$PATH和所有别名,但不知道有这样的脚本。
在到达debian: ls / bin / | grep whatImSearchingFor "
或者,你可以得到一个方便的命令列表,并附有快速描述(只要该命令有一个手册页,大多数都有):
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”并使用默认的寻呼机。)
下面是一个你可以放在bashrc文件中的函数:
function command-search { oldIFS=${IFS} IFS=":" for p in ${PATH} do ls $p | grep $1 done export IFS=${oldIFS} }
使用示例:
$ 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* $
供您参考:IFS是bash用来拆分字符串的变量。
当然,有一些更好的方法可以做到这一点。