ack*_*ack 264 linux terminal command-line
是否有Linux命令列出此终端会话的所有可用命令和别名?
好像你输入'a'并按下了标签,但是对于字母表中的每个字母.或运行'别名'但也返回命令.
为什么?我想运行以下命令,看看命令是否可用:
ListAllCommands | grep searchstr
Run Code Online (Sandbox Code Playgroud)
cam*_*amh 577
您可以使用内置的bash(1) compgen
compgen -c 将列出您可以运行的所有命令.compgen -a 将列出您可以运行的所有别名.compgen -b 将列出您可以运行的所有内置插件.compgen -k 将列出您可以运行的所有关键字.compgen -A function 将列出您可以运行的所有功能.compgen -A function -abck 将一次性列出以上所有内容.检查手册页以了解您可以生成的其他完成.
直接回答你的问题:
compgen -ac | grep searchstr
Run Code Online (Sandbox Code Playgroud)
应该做你想要的.
Ant*_*sma 39
添加到.bashrc
function ListAllCommands
{
echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
-executable -type f -printf '%P\n' | sort -u
}
Run Code Online (Sandbox Code Playgroud)
如果您还想要别名,那么:
function ListAllCommands
{
COMMANDS=`echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
-executable -type f -printf '%P\n'`
ALIASES=`alias | cut -d '=' -f 1`
echo "$COMMANDS"$'\n'"$ALIASES" | sort -u
}
Run Code Online (Sandbox Code Playgroud)
sun*_*256 25
有
type -a mycommand
Run Code Online (Sandbox Code Playgroud)
命令列出$ PATH中使用mycommand的所有别名和命令.可用于检查命令是否存在于多个变体中.除此之外...可能有一些脚本解析$ PATH和所有别名,但不知道任何这样的脚本.
使用"which searchstr".如果它是别名,则返回二进制路径或别名设置
编辑:如果您正在寻找别名列表,您可以使用:
alias -p | cut -d= -f1 | cut -d' ' -f2
Run Code Online (Sandbox Code Playgroud)
将其添加到您喜欢的任何PATH搜索答案中.假设你正在使用bash ..
others命令在嵌入式系统上对我不起作用,因为它们需要bash或更完整的xargs版本(busybox受到限制)。
以下命令应在任何类似Unix的系统上运行。
按文件夹列出:
ls $(echo $PATH | tr ':' ' ')
Run Code Online (Sandbox Code Playgroud)
按名称列出所有命令
ls $(echo $PATH | tr ':' ' ') | grep -v '/' | grep . | sort
Run Code Online (Sandbox Code Playgroud)
或者,您可以获得一个方便的命令列表以及快速描述(只要该命令有一个手册页,大多数命令都有):
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.)
Run Code Online (Sandbox Code Playgroud)
然后你只需按照你想要的方式 grep 即可。
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.)
Run Code Online (Sandbox Code Playgroud)
产量:
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
Run Code Online (Sandbox Code Playgroud)
结果似乎没有排序,因此如果您正在寻找长列表,您可以抛出 | 排序| 到中间,然后将其通过管道传输到寻呼机,例如 less/more/most。翼:
apropos -s 1 '' | grep xdg
Run Code Online (Sandbox Code Playgroud)
它返回名称或简短描述中包含“zip”的所有命令的排序列表,并泵送“less”寻呼机。(您也可以用 $PAGER 替换“less”并使用默认寻呼机。)
试试这个脚本:
#!/bin/bash
echo $PATH | tr : '\n' |
while read e; do
for i in $e/*; do
if [[ -x "$i" && -f "$i" ]]; then
echo $i
fi
done
done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
237154 次 |
| 最近记录: |