Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question

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
/usr/local/bin/git

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

$ which -a git
/usr/local/bin/git
/usr/bin/git

provides every instance of the executable in my PATH.

share|improve this answer
    
This really is the best answer. The top result in which -a foo will tell you the default. –  TJ Luoma Sep 10 '13 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 '13 at 6:55

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

share|improve this answer
    
Btw it works also on other unix systems. –  Matthieu Riegler Sep 6 '13 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.

share|improve this answer
    
I always have trouble correctly using "find". Can you provide an example of how you would use "find" here? –  TMOTTM Sep 9 '13 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 '13 at 21:44
    
I did recommend the "find" command, so I'll post some examples. –  Kaydell Sep 9 '13 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"
    done
}

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.