← 返回命令列表

Linux command

which 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Find the path of a command

which [command]

Find paths of multiple commands

which [command1] [command2]

Show all matching executables

which -a [command]

说明

which searches for executables in the directories listed in the PATH environment variable and prints the path of the first match found. This is useful for determining which version of a command will be executed when multiple versions exist, or for confirming a command is installed and in your PATH. With -a, all matches are shown, revealing if multiple versions exist in different PATH directories. The first listed is the one that would be executed.

参数

-a, --all
Print all matching executables in PATH, not just first

FAQ

What is the which command used for?

which searches for executables in the directories listed in the PATH environment variable and prints the path of the first match found. This is useful for determining which version of a command will be executed when multiple versions exist, or for confirming a command is installed and in your PATH. With -a, all matches are shown, revealing if multiple versions exist in different PATH directories. The first listed is the one that would be executed.

How do I run a basic which example?

Run `which [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a, --all do in which?

Print all matching executables in PATH, not just first