I'm trying to find out how a specific command is defined. I've checked all locations of $PATH
and could not find any file that is named like my command, so it seems to be something else.
Here is an example using nvm, that is not an executable:
me@MacBook:~$ which cat
/bin/cat
me@MacBook:~$ which nvm
me@MacBook:~$ nvm --version
0.33.8
which nvm
simply returns nothing.
What is the equivalent of "which" for commands like this in unix based systems?
The command you are looking for is
type
.type nvm
will show how the shell will interpret the command, so unlikewhich
it'll show aliases, functions and unexported paths too.Here is an answer to a simiar question that advises against the use of
which
for reasons unrelated to the point in question.That said, your assumption that
which
can only see executables is wrong.It does not, however, see functions and aliases by default.
That's why the manpage of which says:
If you define this function in your
.bashrc
and re-source it, you should be able to doand it should give you functions and aliases as well.
However, watch out, if maybe some profile or bashrc already defined something for
which
, that takes precedence (you could find that out, withtype -a which
btw).If I define a script, a function and an alias, called
something
I get withtype -a
:While
which -a
after creating the function gives me: