2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Windows]「このコマンド、どこから実行されてる?」を一発で調べる `where` コマンド

Last updated at Posted at 2026-01-27

はじめに

image.png

Windows の コマンドプロンプト(cmd.exe) を使っていて、こんな経験はありませんか?

  • 「このコマンド、どこから実行されてるんだっけ?」
  • 「PATH 通したはずなのに、なんか挙動おかしくない?」

そんなときに役立つのが、where コマンドです。

正直、最近までちゃんと使ってなかったんですが、知ってからトラブル切り分けが一気に楽になりました。

where とは

実行ファイルが見つかる場所(フルパス)を表示するコマンドです。

  • Linux / macOS の which に相当する存在
  • PATH を上から順に検索した結果をそのまま出してくれる
where <コマンド名>

基本的な使い方

image.png

where code

出力例:

C:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd

つまり、code と打ったときに どの code が実行されているか が一発で分かります。

なぜ where が重要なのか

image.png

Windows は PATH に複数の同名コマンドが存在しがち です。

実際に起きやすいケース:

  • Python が複数バージョン入っている
  • Git for Windows 由来のコマンドと別ツールが被る
  • 以前のインストールが PATH に残っている

「動くけど、想定と違う」 問題の正体を暴くのが where です。

複数ヒットする例(ここが肝)

05_multiple_hits_qiita.png

where python
C:\Python311\python.exe
C:\Users\xxx\AppData\Local\Microsoft\WindowsApps\python.exe

ポイント:

  • 上に出たものほど優先順位が高い
  • この例だと、実行されるのは C:\Python311\python.exe
  • 「WindowsApps の python が邪魔してる」問題の正体が見える

where が何も返さないとき

06_no_output_qiita.png

where node

出力なしの場合:

  • PATH に通っていない
  • そもそもインストールされていない

「コマンドが認識されない」=まず where と覚えておくと便利です。

よく使う定番セット

実務でよく叩くやつ:

where code
where git
where python
where node
where java

新しい開発環境を触るときは、最初にこれだけ打つことも多いです。

PowerShell での注意点

PowerShell では whereエイリアスWhere-Object のエイリアス)になっています。

cmd の where を使いたい場合は:

where.exe code

※ 本記事は cmd.exe 前提です。

まとめ

image.png

where「どのコマンドが、どこから実行されているか」 を可視化する道具です。

  • PATH トラブル・環境差分の切り分けに超強い
  • 覚えることは1つだけ:where <コマンド名>

「なんかおかしい」と思ったら、まず where

派手さはないけど、知ってると確実に助かる Windows の基本コマンドです。

参考リンク

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?