一、命令简介
Linux whereis命令用于查找文件。该指令会在特定目录中查找符合条件的文件。这些文件应属于原始代码、二进制文件,或是帮助文件。该指令只能用于查找二进制文件、源代码文件和man手册页,一般文件的定位需使用locate命令。
Linux which命令用于查找文件。which指令会在环境变量$PATH设置的目录里查找符合条件的文件。
二、使用示例
1、查找bash命令位置
[bdsc@centos7 ~]$ which bash
/bin/bash
[bdsc@centos7 ~]$ whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz
2、whereis命令只查找二进制文件路径
[bdsc@centos7 ~]$ whereis -b bash
bash: /usr/bin/bash
3、whereis命令只查找帮助文档路径
[bdsc@centos7 ~]$ whereis -m bash
bash: /usr/share/man/man1/bash.1.gz
4、which查找并显示所有匹配项
[test@s101 ~]$ which -a bash
/bin/bash
/usr/bin/bash
三、使用语法及参数说明
1、whereis用法
用法:whereis [选项] 文件
2、which用法
用法:which [选项] 命令
3、whereis参数说明
参数 | 参数说明 |
---|---|
-b | 只搜索二进制文件 |
-B <目录> | 定义二进制文件查找路径 |
-m | 只搜索 man 手册 |
-M <目录> | 定义 man 手册查找路径 |
-s | 只搜索源代码 |
-S <目录> | 定义源代码查找路径 |
-f | 终止 <目录> 参数列表 |
-u | 搜索不常见记录 |
-l | 输出有效查找路径 |
4、which参数说明
参数 | 参数说明 |
---|---|
–version, -[vV] | 查看命令版本 |
–help, | 查看命令帮助信息 |
–skip-dot | 跳过路径中以.点开头的目录 |
–skip-tilde | 跳过路径中以~波浪号开头的目录。 |
–show-dot | 不要在输出中将点扩展到当前目录 |
–show-tilde | 为非根目录的主目录输出波浪号 |
–tty-only | 如果不在tty上,请停止处理右侧的选项 |
–all, -a | 打印路径中的所有匹配项,而不只是第一个匹配项 |
–read-alias, -i | 从stdin读取别名列表 |
–skip-alias | 忽略选项-read-alias;不从标准输入读 |
–read-functions | 从stdin读取shell函数 |
–skip-functions | 忽略选项–read-functions; 不从标准输入读 |