Linux command to list all available commands and a

2020-01-26 12:40发布

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 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

20条回答
欢心
2楼-- · 2020-01-26 12:49

Why don't you just type:

seachstr

In the terminal.

The shell will say somehing like

seacrhstr: command not found 

EDIT:

Ok, I take the downvote, because the answer is stupid, I just want to know: What's wrong with this answer!!! The asker said:

and see if a command is available.

Typing the command will tell you if it is available!.

Probably he/she meant "with out executing the command" or "to include it in a script" but I cannot read his mind ( is not that I can't regularly it is just that he's wearing a mind reading deflector )

查看更多
Evening l夕情丶
3楼-- · 2020-01-26 12:50

The others command didn't work for me on embedded systems, because they require bash or a more complete version of xargs (busybox was limited).

The following commands should work on any Unix-like system.

List by folder :

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

List all commands by name

ls $(echo $PATH | tr ':' ' ') | grep -v '/' | grep . | sort
查看更多
叛逆
4楼-- · 2020-01-26 12:51

It's useful to list the commands based on the keywords associated with the command.

Use: man -k "your keyword"

feel free to combine with:| grep "another word"

for example, to find a text editor: man -k editor | grep text

查看更多
Bombasti
5楼-- · 2020-01-26 12:52

For Mac users (find doesn't have -executable and xargs doesn't have -d):

echo $PATH | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm '++x'
查看更多
冷血范
6楼-- · 2020-01-26 12:52

in debian: ls /bin/ | grep "whatImSearchingFor"

查看更多
SAY GOODBYE
7楼-- · 2020-01-26 12:57

You can always to the following:

1. Hold the $PATH environment variable value.
2. Split by ":"
3. For earch entry: 
    ls * $entry 
4. grep your command in that output.

The shell will execute command only if they are listed in the path env var anyway.

查看更多
登录 后发表回答