2

I am looking for some command e.g. match ls which should match commands like ls, alsa asls,.. and return them. I preferably want it to cover both all commands and defined functions. Is there a builtin command/application to do this?

Obviously, I can create my own script for that. But, I am asking just in case anyone knows of existing command/script that does the same?

2 Answers2

4

There is a utility in bash called compgen.

# List all Commands
compgen -c

# List all Commands starting with ls
compgen -c ls

# List all Commands that has 'ls' in it
compgen -c | grep ls
nehcsivart
  • 611
  • 7
  • 14
0

for $PATH'd commands there is:

set -f;   IFS=: PATH=$PATH:
set +f -- $PATH"$PWD"
for d
do    cd   -- "$d" &&
      hash -- *"$command"*
done; hash; PATH=${PATH%:}
mikeserv
  • 58,310