千家信息网

which命令使用方法

发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,NAMEwhich - show the full path of (shell) commands 显示命令的完整路径。SYNOPSIS which [option
千家信息网最后更新 2025年02月02日which命令使用方法

NAME
which - show the full path of (shell) commands 显示命令的完整路径。
SYNOPSIS

                which   [options]  [--]  programname [...]

DESCRIPTION
which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash(1).
which可以带一个或多个参数。对于每一个参数,当这个参数被键入到shell命令提示符中,它打印可执行文件的完整路径到标准输出。它用bash相同的算法(即显示最先被搜寻到的哪一个),它在PATH环境变量列出来的目录执行这个搜索可执行文件或者脚本文件。
实例1:查找文件、显示命令路径

说明:
which是根据使用者所配置的PATH变量内的目录去搜寻可运行挡的!所以,不同的PATH配置内容所找到的命令当然不一样。
实例2:用which 去找which

说明:

竟然会有两个 which ,其中一个是 alias 这就是所谓的『命令别名』,意思是输入 which 会等於后面接的那串命令!
实例3:找出cd这个命令

说明:
cd 这个常用的命令竟然找不到?为什么呢?这是因为cd是bash内建命令!但是which默认是找PATH内所包含的目录,所以当然一定找不到。

0