Bohack

Check In and Tune Out!
 
 
« Simple Server Ping and Reboot Monitor
Redirect HTTP to SSL with IIS »

Windows Version of the Linux / UNIX ‘which’ Command



During the day I always have a command window open on my desktop. It helps get simple tasks done; like reseting a password for a user or opening an ssh session with a remote box. I have a multitude of Windows command or cmd scripts that help me through out the day. Often I may want to change or tweak a script and then the hunt is on… Which directory was it created in? I know that it is in the path; because I can just execute it without typing it’s full path, but where is it?


As best practice; I recommend to keep all scripts in a folder at the base of the %systemdrive% or C: drive and include it in your system %path% variable. This makes it easy to take your tools with you, when you redo your laptop or desktop. I personally use a folder called ‘sys’, but you can select your own. Just be sure to include the folder in your %path% variable.

Even if you put all your files in a particular folder sometimes your just looking for that particular file in the path. So I have written a Windows version of the UNIX ‘which’ command. Just copy the script below and save it as ‘which.cmd’ in your ‘sys’ folder.

Copy and Paste the script below into notepad and save it as “which.cmd”

@echo off
rem /
rem / which.cmd - 110108 - bohack.com 2008i     /
rem / Windows version of the UNIX which command /
rem /
setlocal
if [%1]==[] goto :errhand
set whichpath=%~dp$path:1
if [%whichpath%]==[] goto :end
echo %whichpath%%1
goto end

:errhand
echo.
echo Usage: %0 (filename to search in path)

:end
endlocal

Tags: Linux / Unix, Script, Windows

This entry was posted on Monday, November 24th, 2008 at 2:38 pm and is filed under Windows.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.

Comments are closed.

  • Channels

    • Beer (2)
    • Blog (1)
    • Exchange (2)
    • Ham Radio (1)
    • Homebrew (3)
    • Linux / Unix (4)
    • Misc (1)
    • Mods (4)
    • Networking (1)
    • Programming (4)
    • Recipes (2)
    • Scripts (7)
    • Security (1)
    • Software (2)
    • Spam (1)
    • Telco (7)
    • Virtual PC (1)
    • VMware (3)
    • VOIP (3)
    • Windows (16)
    • Windows 2008 (4)
    • Windows 7 (5)
  • Archives

    • September 2012
    • April 2012
    • March 2012
    • February 2012
    • January 2012
    • November 2011
    • September 2011
    • July 2011
    • April 2011
    • February 2011
    • January 2011
    • October 2010
    • August 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • June 2009
    • May 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Links

    • Blogarama Blogarama – The Blog Directory
    • BlogHub Blog Directory
    • Blogrankings Technology Blogs – Blog Rankings
    • Blogville.us blogville.us
    • Buzzerhut free directory | buzzerhut.com
    • Ontoplist Online Marketing
    • Primechoiceautoparts Discount Auto Parts
    • PTC My Employer
 

  Copyright - Bohack 2025 ©