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?

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
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%:}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.