UNIX-like ‘which’ Utility for Windows
'which' is a Unix command used to identify the location of executables by searching in the directories listed in the
PATH environment variable.
There are some 3rd party tools that implement the ‘which’ functionality in Windows, but do you know that the recent versions of Windows actually come with a tool called
'where' that is able to accomplish the same task as the 'which' utility ? Now, let's see how we can use that utility to determine the location of the
d:\util>where java C:\Windows\System32\java.exe
A couple of years back, I also wrote a simple batch file that actually implements the same functionality of
'which'. Here's the code:
@echo off :: check for illegal charecters if "%1"=="" goto USAGE echo %1 | find /v ":" | find /v "\" | find /v "*" | find /v "?" | find /v "," | find /v ";" | find /v "/" | find "%1" > nul if errorlevel 1 goto USAGE :: actual 'which' logic for %%a in (.;%pathext%) do for %%b in (%1%%a) do ( echo %%~f$PATH:b | find /i "%1" ) goto END :USAGE :: Help screen: echo. echo UNIX-like which utility for Windows echo Written by Ibrahim - www.digitalinternals.com echo. echo Usage: which executable_name echo. echo you may specify executable_name with or without echo extension, but without a drive, path, echo spaces or wildcards character(s). echo. :END
Copy the above code to a batch file called "which.bat" and place it somewhere in your machine's PATH.
Latest posts by Mohamed Ibrahim (see all)
- SSH Port Forwarding for TCP and UDP Packets - August 31, 2014
- Fix for WiFi Push Notifications Delay on Android - August 23, 2014
- Unix / Linux: Delete Files Older Than x Days - August 13, 2014
- How to Download The Business Times Print Edition in PDF for Free - August 5, 2014
- Shell Script: Echo to Stderr - July 27, 2014