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
/usr/bin
Anyone?
The Korn shell,
ksh
, offers thewhence
built-in, which identifies other shell built-ins, macros, etc. Thewhich
command is more portable, however.In the TENEX C Shell, tcsh, one can list a command's location(s), or if it is a built-in command, using the
where
command e.g.:If you're using Bash or zsh, use this:
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
.In Bash, for functions
type -a
will also display the function definition. You can usedeclare -f functionname
to do the same thing (you have to use that for zsh, sincetype -a
doesn't).Like this:
PATH
is an environment variable, and can be displayed with the echo command:It's a list of paths separated by the colon character '
:
'The
which
command tells you which file gets executed when you run a command:sometimes what you get is a path to a symlink; if you want to trace that link to where the actual executable lives, you can use
readlink
and feed it the output ofwhich
:The
-f
parameter instructsreadlink
to keep following the symlink recursively.Here's an example from my machine: