Find path to an executable
How to find the exact path to an executable file present in your PATH
. I.e. commands you can call by just their names.
E.g. what executable gets called when I type find
and hit enter?
$ hypothetical-find-path find
/path/to/find
3 answers
which
only tells you about a path that would be found in PATH. Often, people who think they have this question have a more general question - i.e., what will be used when the named command is requested. In particular, aside from being executables on PATH, commands can also refer to shell builtins.
The type
command gives this information. With the -a
flag, it can also disclose multiple implementations of a command, in preference order. For example, on my system:
$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
The echo
executable on my system is hard-linked in those locations, but neither would ordinarily be used (as the shell builtin would be preferred).
2 comment threads
If you need this in a portable POSIX-compliant script, you should not use which
but this instead:
command -v find
0 comment threads