@icarus's great solution works for functions, as long as they are defined literally and not the result of an eval
of the contents of another file (in which the file with the eval
will show up as the source). It will not print the source file of aliases, shell built-ins (like echo
) and executables (binary or not), and I believe this information is not available in general. Some commands might print their source files (and may even be truthful about it), either in the course of normal execution or in response to a signal.
__git_ps1
is defined in /usr/share/git/git-prompt.sh
and /usr/share/git/completion/git-prompt.sh
on my system, Arch Linux, so it may be the same for you.
Have a look at the Invocation section of man bash
if you want look for commands specifically sourced at the start of the shell - they may source other files which in turn source other files.
$PATH
, thentype
won't work. You might want to try just usingfind
orlocate
.locate
will be much faster, since it uses a pre-existing database, but it won't work if the command was installed just recently.