I have a program called PyMOL installed multiple times on my machine. One was installed by MacPorts, one was installed through the developers distribution channel and so on. One is in /opt/local/bin, the other is in /i/have/no/clue.

I know I can use "which pymol" to see, where the one that is executed is located, but how can I get the location of the other ones with the same name?

4 Answers 4


You have the right command and just need to set the proper option:

which -a pymol will show all instances of the executable pymol located within your PATH.

For example, on my laptop I have git installed in two places:

$ which git

provides what will be run when I use the command git.

$ which -a git

provides every instance of the executable in my PATH.

  • This really is the best answer. The top result in which -a foo will tell you the default.
    – TJ Luoma
    Sep 10, 2013 at 20:19
  • OK, but how about instances not in $PATH? I'm actually after the instances I don't know about, and which therefore I have not added to $PATH.
    – TMOTTM
    Sep 12, 2013 at 6:55

whereis pymol should show you all matches that are in your executable path.

  • Btw it works also on other unix systems. Sep 6, 2013 at 12:19

You could use "find" or "locate" and then run the results through "grep".

This will give you more than the results of "which" or "whereis" which will only show things on $PATH.

"locate" is faster, but uses an index which isn't always up-to-date.

"find" is slower, doing a recursive search of everything, but it produces all results -- not just the results that have been indexed like "locate" does.

  • I always have trouble correctly using "find". Can you provide an example of how you would use "find" here?
    – TMOTTM
    Sep 9, 2013 at 20:44
  • I have trouble using the "find" command too. That's why I like a GUI interface such as what is in the "Easy Find" app: devontechnologies.com/download/products.html
    – Kaydell
    Sep 9, 2013 at 21:44
  • I did recommend the "find" command, so I'll post some examples.
    – Kaydell
    Sep 9, 2013 at 21:45

At least according to its man page, whereis doesn't search in $PATH but in the result of sysctl user.cs_path (which doesn't contain any additional directories added by the user's profile). To search for the command based on the actual $PATH you could use a shell function like

function whereis() {
    for p in ${PATH//:/ }; do
        [[ -x "$p/$1" ]] && echo "$p"

or (for your specific case) run

for p in ${PATH//:/ }; do [[ -x "$p"/pymol ]] && echo "$p" ; done

PS: The space character near the end of${PATH...}is essential for this to work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .