# [PowerShell] 실행 파일, 너의 위치는?

bash에서는 `which`를 cmd에서는 `where`을 이용해서 실행 파일의 위치를 찾을 수 있다.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649520434147/EjLD9keEl.png)

그러나 powershell에서는 `where`는 아무것도 나오지 않고 `which` 명령어는 지원하지 않는다.

> 이는 powershell에서 `where`는 다른 기능을 수행하기 때문이다

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649520546425/omNXGNX-Y.png)

그렇다면 powershell에는 실행 파일의 위치를 찾는 명령어를 제공하지 않느냐?  
-> 그건 아니다.

powershell에서는 `Get-Command`라는 명령어를 통해서 실행 파일을 찾을 수 있다.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649520804252/dn9ZzCR0B.png)

그렇지만 웃기게도 정작 중요한 위치 정보는 창을 크게 하지 않는 이상 잘려서 나오고 명령어도 길어서 불편하다.  
따라서 위치 정보만 나오게 하도록 변경한 함수를 `$PROFILE` 파일에 등록하면 된다.

사용자마다 `$PROFILE` 파일의 위치가 다를 텐데 그냥 powershell에서 다음 명령어를 입력하면 열린다.

```
notepad $PROFILE
```
> `$PROFILE` 파일은 powershell이 열릴 때마다 실행되는 파일로 `.bashrc`, `.zshrc`와 같은 것이라고 생각하면 편하다

처음 열면 새로운 파일을 생성하고 저장한다.

```
function which ($command) {
  Get-Command -Name $command -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
```

저장하고 다시 powershell을 켠 후 `which java`를 입력하면

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649521073162/mfSU_yRQU.png)

위와 같이 깔끔하게 나온다.

