Esiste un equivalente del comando Unix whereis in Windows?
In modo che potessi capire dove sono effettivamente i comandi che posso eseguire.
Il comando where fa quello che vuoi e risale almeno al resource kit per Windows 98, ed è incluso di default in Server 2003, Vista e più recente:
C:\>where csc
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe
C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
Se eseguito senza argomenti (su Vista), risulta in uno dei miei messaggi preferiti:
C:\>where
ERROR: The operation completed successfully.
Se esegui in PowerShell, assicurati di includere ".exe" per distinguere da qualsiasi "alias" o script lungo il percorso. ('where' è un alias tipico di Where-Object.ps1)
C:\> where.exe where.exe
C:\Windows\System32\where.exe
Per favore, usa where command:
> where app.exe
È il modo migliore per raggiungere il tuo obiettivo.
È inoltre possibile utilizzare il comando PowerShell:
> $env:path.Split(';') | gci -Filter app.exe
e la versione espansa ha questo aspetto:
> $env:path.Split(';') | select -Unique | ? {$_ -and (test-path $_)} | gci -Filter app.exe
hackerish che.cmd:
@echo off
@set PATH=.;%PATH%
@rem
@rem about: something similar like the unix-alike-which, but with
@rem within pure cmd
@rem
if "%1" == "" (
@echo Usage:
@echo.
@echo which 'cmd'
@echo.
@echo.if 'cmd' is not found, ERRORLEVEL is set to 1
@echo.
) else (
( @for %%f in (%1 %1.exe %1.cmd %1.bat %1.pif) do if not "%%~$PATH:f" == "" ( @echo %%~$PATH:f ) else @set ERRORLEVEL=1)
)
Da qualche parte "là fuori" ho trovato questo file batch whereis.bat
:
@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i
Aggiornamento: forse l'ho trovato qui .
Esiste almeno una porta Windows per l'utility which
.
function find ($string) {
Get-ChildItem -Path 'c:\' -Recurse -Filter $string;
}
function whereis ($string) {
$superpath = "$env:Path;C:\Program Files;C:\Program Files (x86)";
(echo $superpath).Split(';') | Get-ChildItem -Recurse -Filter $string;
}
Esempio:
PS> trova Mozilla.admx
Directory: C:\Windows\PolicyDefinitions
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/27/2016 12:22 PM 37146 Mozilla.admx
PS> whereis firefox.exe
Directory: C:\Program Files\Mozilla Firefox
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/21/2017 5:30 PM 477136 firefox.exe
Lo stavo cercando oggi e visto che sono su XP senza il resource kit, ho scelto PowerShell con il seguente comando:
dir -path c:\ -filter ffmpeg.* -r
Un approccio diverso (GUI), ma guarda Tutto .