Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I have a long and involved PATH and I type the name of some command, how do I find out where the EXE or BAT file actually lives. I thought TRUENAME did this but it's gone from XP and I'm not sure it did exactly what I want.

So I want to be able to type

WHEREIS "Obscure Tool.exe"

and I get:

C:\Program Files\Obscure Tools Limited\Obscure Tool\Obscure Tool.exe

when the folder C:\Program Files\Obscure Tools Limited\Obscure Tool\ is on my path. What is WHEREIS called, or can it be done with a batch file?

share|improve this question
    
truename does something else. –  JdeBP Aug 27 '11 at 13:40

5 Answers 5

up vote 3 down vote accepted

Using powershell you can use the Get-Command tool.exe

share|improve this answer

If you have GnuWin32 it's as simple as:

which ObscureTool.exe

Even better, if you're invoking it by name only (without an extension, as in "ObscureTool"), it'll still find the right thing. This might be an issue if you have two "executable" files: "ObscureTool.exe" and "ObscureTool.bat". In this case, WHICH will find the one that occurs first in the path. In this case, you'd merely say"

which ObscureTool
share|improve this answer
    
+1 for GnuWin32 pointer. –  rossmcm Aug 24 '11 at 21:19

It all depends from what command interpreter one is running, and there isn't an external utility that is going to do this properly in all cases. This is for a very imporant reason:

Different command interpreters look for commands in different ways.
Only a command built in to each individual command interpreter will truly know what will be invoked by a particular command name.

  • For JP Software's TCC, simply use its built-in which command. This understands TCC's aliases, executable extensions, and path search algorithm.
    [c:\]which mspaint dir
    mspaint is an external : C:\Windows\system32\mspaint.exe
    dir is an internal command
    [c:\]
  • For the Korn shell, ksh, as available in the SFUA utility toolkit (which run in the Subsystem for UNIX-based Applications that comes right there in the box with Windows 7 Ultimate edition and Windows Server 2008 R2) use its built-in whence command. This understands the Korn shell's aliases, functions, built-in commands, and so forth.
    $ whence -v ls
    ls is a tracked alias for /bin/ls
    $
  • For the Bourne-Again shell, bash, as available for Services for Unix Applications as well as in Cygwin, use its built-in type command. This understands the Boune-Again shell's aliases, functions, built-in commands, and so forth.
    $ type '['
    [ is a shell builtin
    $
  • For Microsoft's command interpreter, cmd, you're out of luck. There's no built-in command for doing this; and although one can employ external commands that will replicate the path search algorithm, those commands will not necessarily (or even usually) recognize aliases and built-in commands. For examples: Here is the GnuWin32 which command failing to recognize dir (in contrast with TCC's built-in which command above):
    C:\>which dir
    which: no dir in (.;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem)
    C:\>
    And here is the where command mentioned by grawity below failing in exactly the same fashion:
    C:\>where dir
    INFO: Could not find files for the given pattern(s).
    C:\>
share|improve this answer
2  
Recent Windows versions come with a tool named where (which is still an external command, though). –  grawity Sep 8 '11 at 21:28
    
I wouldn't say "where" is failing; its spec is to search the current directory then the PATH for files matching the search pattern, not commands. It should be available from Vista and above. –  RJFalconer Feb 12 '13 at 10:37

You could use 'dir', the directory listing tool:

dir "c:\Obscure Tool.exe" /s/b

The /s means search subdirectories, and since you are starting in the root folder (C:) it will search all the folders on that drive.
The /b makes it display the result in "bare" format with no heading information or summary (ie. you will just get the path and filename).

share|improve this answer
1  
+1 This is my favorite brute-force search method, if Windows' GUI search tools fail me for whatever reason (though since Vista, they've gotten better, in my opinion). –  Ben Richards Aug 23 '11 at 0:31
2  
this will list ALL files called Obscure Tool. Not the one in the path. –  Keltari Aug 23 '11 at 0:32
1  
Everything.exe is always faster than a normal search through lots of directories. It does it immediately. Though probably no command line option like output on command line. –  barlop Sep 3 '11 at 21:06

I am running regular Windows 7 and simply typing "where java.exe" seems to work great without any additional software.

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.