Linux command to list all available commands and aliases

0 votes
asked Jun 4, 2009 by ack

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

21 Answers

0 votes
answered Jan 4, 2009 by oscarryz

Why don't you just type:


In the terminal.

The shell will say somehing like

seacrhstr: command not found 


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 )

0 votes
answered Jan 4, 2009 by gabriel-sosa

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

0 votes
answered Jan 4, 2009 by oscarryz

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.

0 votes
answered Jan 4, 2009 by nikudesu

The problem is that the tab-completion is searching your path, but all commands are not in your path.

To find the commands in your path using bash you could do something like :

for x in echo $PATH | cut -d":" -f1; do ls $x; done

0 votes
answered Jan 4, 2009 by craig-wright

Here's a function you can put in your bashrc file:

function command-search

   for p in ${PATH}
      ls $p | grep $1

   export IFS=${oldIFS}

Example usage:

$ command-search gnome

FYI: IFS is a variable that bash uses to split strings.

Certainly there could be some better ways to do this.

0 votes
answered Jan 4, 2009 by lb40

maybe i'm misunderstanding but what if you press Escape until you got the Display All X possibilities ?

0 votes
answered Jun 4, 2009 by sunny256

There is the

type -a mycommand

command which lists all aliases and commands in $PATH where mycommand is used. Can be used to check if the command exists in several variants. Other than that... There's probably some script around that parses $PATH and all aliases, but don't know about any such script.

0 votes
answered Jun 4, 2009 by aaron

Use "which searchstr". Returns either the path of the binary or the alias setup if it's an alias

Edit: If you're looking for a list of aliases, you can use:

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

Add that in to whichever PATH searching answer you like. Assumes you're using bash..

0 votes
answered Jun 4, 2009 by igor-krivokon

Try to press ALT-? (alt and question mark at the same time). Give it a second or two to build the list. It should work in bash.

0 votes
answered Jun 4, 2009 by victor-hugo

Try this script:

echo $PATH  | tr : '\n' | 
while read e; do 
    for i in $e/*; do
        if [[ -x "$i" && -f "$i" ]]; then     
            echo $i
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter