You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.4 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# **which**
## 说明
**which命令** 用于查找并显示给定命令的绝对路径环境变量PATH中保存了查找命令时需要遍历的目录。which指令会在环境变量$PATH设置的目录里查找符合条件的文件。也就是说使用which命令就可以看到某个系统命令是否存在以及执行的到底是哪一个位置的命令
```info
--skip-dot Skip directories in PATH that start with a dot
--skip-tilde Skip directories in PATH that start with a tilde
--show-dot Don't expand a dot to current directory in output
--show-tilde Output a tilde for HOME directory for non-root
--tty-only Stop processing options on the right if not on tty
--all, -a 输出所有在PATH匹配的可执行文件
--read-alias, -i Read list of aliases from stdin
--skip-alias Ignore option --read-alias; don't read stdin
--read-functions Read shell functions from stdin
--skip-functions Ignore option --read-functions; don't read stdin
```
## 实例
```sh
# 说明which是根据使用者所配置的 PATH 变量内的目录去搜寻可运行档的所以不同的 PATH 配置内容所找到的命令当然不一样的
which cd # 用 which 去找出 cd
# cd 这个常用的命令找不到为什么呢这是因为cd是bash内建的命令但是 which 默认是找 PATH 内所规范的目录,所以一定找不到的!
```