How to find directory of some command?


I know that when you are on shell, the only commands that can be used are the ones that can be found on some directory set on PATH.
Even I don’t know how to see what dirs are on my PATH variable (and this is another good question that could be answered), what I’d like to know is:

I come to shell and write:

$ lshw

I want to know a command on shell that can tell me WHERE this command is located. In other words, where this "executable file" is located?

Something like:

$ location lshw


If you’re using Bash or zsh, use this:

type -a lshw

This will show whether the target is a builtin, a function, an alias or an external executable. If the latter, it will show each place it appears in your PATH.

bash$ type -a lshw
lshw is /usr/bin/lshw
bash$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
bash$ zsh
zsh% type -a which
which is a shell builtin
which is /usr/bin/which

In Bash, for functions type -a will also display the function definition. You can use declare -f functionname to do the same thing (you have to use that for zsh, since type -a doesn’t).

Answered By – Dennis Williamson

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published