Windows 명령 행에 '어느 것'과 동일합니까?
질문
때로는 경로 문제가 있으므로 내 자신의 CMD 스크립트 중 하나가 다른 프로그램 (경로의 이전)에서 숨겨진 (Shaked)되는 경우, Windows 명령 줄에서 프로그램에 대한 전체 경로를 찾을 수 있기를 원합니다.그 이름 만.
UNIX 명령과 동등한 것이 있습니까? '
UNIX에서 어떤 명령이 주어진 명령의 전체 경로를 인쇄하여 이러한 섀도 잉 문제를 쉽게 찾고 복구 할 수 있습니다.
답변
Windows Server 2003 이상 (Windows XP 32 비트 후에는 아무 것도)은 실행 가능한 명령뿐 아니라 모든 유형의 파일과 일치하는 모든 유형의 파일과 일치하는지에 대해 WHERE.EXE 프로그램을 제공합니다.(CD와 같은 내장 된 쉘 명령과 일치하지 않습니다.) 와일드 카드를 사용할 수도 있으므로 NT *가 % PATH %의 모든 파일을 찾습니다. 이름이 NT로 시작하는 현재 디렉토리.
어디서 /?도와주기 위해.
Windows PowerShell은 어디에서 객체 Cmdlet의 별칭을 정의하므로 .EXE.exe를 원하면 .exe 확장자를 생략하는 대신 전체 이름을 입력해야합니다.또는 별칭을 설정할 수 있습니다.
Set-Alias which where.exe
업데이트 : Get-Command (별칭 : GCM)를 사용하면 ps의 원시 이후에 권장되며 별칭, cmdlet, 실행 파일 및 함수를 모두 가져옵니다.예시:
gcm notepad*
답변
Windows 버전의 Windows에는 Windows 명령은 다음과 같이 환경 변수 수정자를 사용하여 Windows XP 에서이 작업을 수행 할 수도 있습니다.
c:\> for %i in (cmd.exe) do @echo. %~$PATH:i
C:\WINDOWS\system32\cmd.exe
c:\> for %i in (python.exe) do @echo. %~$PATH:i
C:\Python25\python.exe
추가 도구가 필요 없으며 사용하려는 환경 변수 (Path Format)를 대체 할 수 있기 때문에 경로에만 국한되지 않습니다.
또한 PateExt (Windows 자체로서)에서 모든 확장을 처리 할 수있는 것을 원한다면이 트릭을 수행합니다.
@echo off
setlocal enableextensions enabledelayedexpansion
:: Needs an argument.
if "x%1"=="x" (
echo Usage: which ^<progName^>
goto :end
)
:: First try the unadorned filenmame.
set fullspec=
call :find_it %1
:: Then try all adorned filenames in order.
set mypathext=!pathext!
:loop1
:: Stop if found or out of extensions.
if "x!mypathext!"=="x" goto :loop1end
:: Get the next extension and try it.
for /f "delims=;" %%j in ("!mypathext!") do set myext=%%j
call :find_it %1!myext!
:: Remove the extension (not overly efficient but it works).
:loop2
if not "x!myext!"=="x" (
set myext=!myext:~1!
set mypathext=!mypathext:~1!
goto :loop2
)
if not "x!mypathext!"=="x" set mypathext=!mypathext:~1!
goto :loop1
:loop1end
:end
endlocal
goto :eof
:: Function to find and print a file in the path.
:find_it
for %%i in (%1) do set fullspec=%%~$PATH:i
if not "x!fullspec!"=="x" @echo. !fullspec!
goto :eof
실제로 모든 가능성을 반환하지만 특정 검색 규칙에 대해 쉽게 조정할 수 있습니다.
답변
PowerShell에서 get-mode는 $ env : 경로에서 실행 파일을 찾습니다.
$ Get-Command eventvwr
CommandType Name Definition
----------- ---- ----------
Application eventvwr.exe c:\windows\system32\eventvwr.exe
Application eventvwr.msc c:\windows\system32\eventvwr.msc
그리고 PowerShell이므로 별칭을 정의하므로 정의 할 수 있습니다.
$ sal which gcm # short form of `Set-Alias which Get-Command`
$ which foo
...
PowerShell 명령은 실행 파일 (.exe, .ps1 등)뿐만 아니라.또한 cmdlet, 함수, 별칭, $ env : pathext 등에 설정된 cmdlet, 함수, 별명, 사용자 정의 실행 가능 접미사 등이 될 수 있습니다. get-moden은 이러한 명령을 모두 찾아보고 나열 할 수 있습니다 (Bash의 유형과 비슷한 -A foo).이렇게만으로는 일반적으로 실행 파일을 찾는 것으로 제한된 where.exe, dathol.exe 등보다 낫습니다.
이름의 일부만 사용하여 실행 파일 찾기
$ gcm *disk*
CommandType Name Version Source
----------- ---- ------- ------
Alias Disable-PhysicalDiskIndication 2.0.0.0 Storage
Alias Enable-PhysicalDiskIndication 2.0.0.0 Storage
Function Add-PhysicalDisk 2.0.0.0 Storage
Function Add-VirtualDiskToMaskingSet 2.0.0.0 Storage
Function Clear-Disk 2.0.0.0 Storage
Cmdlet Get-PmemDisk 1.0.0.0 PersistentMemory
Cmdlet New-PmemDisk 1.0.0.0 PersistentMemory
Cmdlet Remove-PmemDisk 1.0.0.0 PersistentMemory
Application diskmgmt.msc 0.0.0.0 C:\WINDOWS\system32\diskmgmt.msc
Application diskpart.exe 10.0.17... C:\WINDOWS\system32\diskpart.exe
Application diskperf.exe 10.0.17... C:\WINDOWS\system32\diskperf.exe
Application diskraid.exe 10.0.17... C:\WINDOWS\system32\diskraid.exe
...
사용자 정의 실행 파일 찾기
실행 파일이 실행 파일 (+ x) 비트 세트가있는 파일이있는 UNIX와 달리 Windows의 실행 파일은 $ Path Env에 지정된 디렉토리 중 하나에있는 파일입니다.Filename 접미사가 $ PathExt Env에서 이름이 지정된 변수입니다.변수 (기본값은 .com; .exe; .bat; .cmd; .vbs; .vbe; .js; .jse; .wsf; .wsh; .cpl).
GET-Command는 또한이 env를 명예 깊게 생각합니다.변수, 사용자 정의 실행 파일을 나열하도록 확장 될 수 있습니다.예를 들어,
$ $Env:PATHEXT="$Env:PATHEXT;.dll;.ps1;.psm1;.py" # temporary assignment, only for this shell's process
$ gcm user32,kernel32,*WASM*,*http*py
CommandType Name Version Source
----------- ---- ------- ------
ExternalScript Invoke-WASMProfiler.ps1 C:\WINDOWS\System32\WindowsPowerShell\v1.0\Invoke-WASMProfiler.ps1
Application http-server.py 0.0.0.0 C:\Users\ME\AppData\Local\Microsoft\WindowsApps\http-server.py
Application kernel32.dll 10.0.17... C:\WINDOWS\system32\kernel32.dll
Application user32.dll 10.0.17... C:\WINDOWS\system32\user32.dll
자세한 옵션과 예제는 Get-Command를 참조하십시오.
답변
Windows PowerShell에서 :
set-alias which where.exe
답변
PowerShell이 설치된 경우 (내가 추천), 다음 명령을 거친 동등한 (실행 파일의 이름을 위해 대체 프로그램 이름 대체)으로 사용할 수 있습니다.
($Env:Path).Split(";") | Get-ChildItem -filter programName*
여기 : 내 망위!Powershell Ghantershell
답변
GNUWIN32 도구는 다른 유닉스 도구의 전체 슬리와 함께 있습니다.
출처:https://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-the-windows-command-line
최근댓글