multiwhich

The “which” Unix command lists the location of the first matching executable in your PATH. The GNU version of “which” has several extra features including the ability to display all matching executables in your PATH, not just the first. This is useful for finding duplicates, etc. Unfortunately, whatever version of “which” is included in Mac OS X (and MacPorts) doesn’t have these extra features.

A quick Google search didn’t turn up anything, and I was in a shell scripting mood when I needed it, so rather than downloading and compiling GNU which I whipped up my own, “multiwhich”:

#!/bin/sh

for PATHDIR in `echo $PATH | tr ":" " "`
do
    sh -c "ls -1 $PATHDIR/$1" 2> /dev/null
done

Simply put this somewhere in your PATH with execute permissions, and type “which command“.

One other accidental “feature” of this script is the ability to list every executable in your PATH. This is great for finding duplicates:

multiwhich | sort | uniq -c | sort -n

It’s probably not the most elegant way to do it, but it serves it’s purpose. Perhaps someone will find it useful…

Update: I modified the multiwhich script slightly to support wildcards like “*” and “?”. You can now do things like “multiwhich x*” to get all binaries beginning with “x”, etc.

  • http://auburnfamilydental.com/ Margarett Zielinski

    The “which” Unix command lists the location of the first matching executable in your PATH. 

  • http://socialturnon.com/ Idell Stpierre

    They spent more time protecting the protocol than making sure it works well.

  • http://www.dickies.ca/ Pia Whitlow

    The “which” Unix command lists the location of the first matching executable .

  • http://www.acantohotels.com/ Delta Schubert

    This is useful for finding duplicates, etc. Unfortunately.