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?

VarunAgw
  • 567
  • 4
  • 18
  • Possibly related: [What are commands to find shell keywords, built in functions and user defined functions?](http://unix.stackexchange.com/questions/63073/what-are-commands-to-find-shell-keywords-built-in-functions-and-user-defined-fu/) – steeldriver Jan 23 '16 at 19:05

2 Answers2

5

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
  • 621
  • 7
  • 13
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
  • 57,448
  • 9
  • 113
  • 229